Skip to content

Commit

Permalink
style: simplify string formatting (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Aug 13, 2024
1 parent 7829e0e commit 1617041
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/autobahn-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ fn get_case_count() -> Result<u32> {
}

fn update_reports() -> Result<()> {
let (mut socket, _) = connect(&format!("ws://localhost:9001/updateReports?agent={}", AGENT))?;
let (mut socket, _) = connect(&format!("ws://localhost:9001/updateReports?agent={AGENT}"))?;
socket.close(None)?;
Ok(())
}

fn run_test(case: u32) -> Result<()> {
info!("Running test case {}", case);
let case_url = &format!("ws://localhost:9001/runCase?case={}&agent={}", case, AGENT);
let case_url = &format!("ws://localhost:9001/runCase?case={case}&agent={AGENT}");
let (mut socket, _) = connect(case_url)?;
loop {
match socket.read()? {
Expand Down
4 changes: 2 additions & 2 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ fn main() {
println!("Response HTTP code: {}", response.status());
println!("Response contains the following headers:");
for (ref header, _value) in response.headers() {
println!("* {}", header);
println!("* {header}");
}

socket.send(Message::Text("Hello WebSocket".into())).unwrap();
loop {
let msg = socket.read().expect("Error reading message");
println!("Received: {}", msg);
println!("Received: {msg}");
}
// socket.close(None);
}
2 changes: 1 addition & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
println!("The request's path is: {}", req.uri().path());
println!("The request's headers are:");
for (ref header, _value) in req.headers() {
println!("* {}", header);
println!("* {header}");
}

// Let's add an additional header to our response to the client.
Expand Down
4 changes: 2 additions & 2 deletions examples/srv_accept_unmasked_frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
println!("The request's path is: {}", req.uri().path());
println!("The request's headers are:");
for (ref header, _value) in req.headers() {
println!("* {}", header);
println!("* {header}");
}

// Let's add an additional header to our response to the client.
Expand All @@ -40,7 +40,7 @@ fn main() {
loop {
let msg = websocket.read().unwrap();
if msg.is_binary() || msg.is_text() {
println!("received message {}", msg);
println!("received message {msg}");
}
}
});
Expand Down
8 changes: 3 additions & 5 deletions src/handshake/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ mod tests {
#[test]
fn random_keys() {
let k1 = generate_key();
println!("Generated random key 1: {}", k1);
println!("Generated random key 1: {k1}");
let k2 = generate_key();
println!("Generated random key 2: {}", k2);
println!("Generated random key 2: {k2}");
assert_ne!(k1, k2);
assert_eq!(k1.len(), k2.len());
assert_eq!(k1.len(), 24);
Expand All @@ -349,9 +349,7 @@ mod tests {
Upgrade: websocket\r\n\
Sec-WebSocket-Version: 13\r\n\
Sec-WebSocket-Key: {key}\r\n\
\r\n",
host = host,
key = key
\r\n"
)
.into_bytes()
}
Expand Down
4 changes: 2 additions & 2 deletions src/handshake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<Role: HandshakeRole> fmt::Debug for HandshakeError<Role> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
HandshakeError::Interrupted(_) => write!(f, "HandshakeError::Interrupted(...)"),
HandshakeError::Failure(ref e) => write!(f, "HandshakeError::Failure({:?})", e),
HandshakeError::Failure(ref e) => write!(f, "HandshakeError::Failure({e:?})"),
}
}
}
Expand All @@ -73,7 +73,7 @@ impl<Role: HandshakeRole> fmt::Display for HandshakeError<Role> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
HandshakeError::Interrupted(_) => write!(f, "Interrupted handshake (WouldBlock)"),
HandshakeError::Failure(ref e) => write!(f, "{}", e),
HandshakeError::Failure(ref e) => write!(f, "{e}"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/frame/coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl fmt::Display for Data {
Data::Continue => write!(f, "CONTINUE"),
Data::Text => write!(f, "TEXT"),
Data::Binary => write!(f, "BINARY"),
Data::Reserved(x) => write!(f, "RESERVED_DATA_{}", x),
Data::Reserved(x) => write!(f, "RESERVED_DATA_{x}"),
}
}
}
Expand All @@ -57,7 +57,7 @@ impl fmt::Display for Control {
Control::Close => write!(f, "CLOSE"),
Control::Ping => write!(f, "PING"),
Control::Pong => write!(f, "PONG"),
Control::Reserved(x) => write!(f, "RESERVED_CONTROL_{}", x),
Control::Reserved(x) => write!(f, "RESERVED_CONTROL_{x}"),
}
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ impl CloseCode {
impl fmt::Display for CloseCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let code: u16 = self.into();
write!(f, "{}", code)
write!(f, "{code}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/frame/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ mod tests {
#[test]
fn display() {
let f = Frame::message("hi there".into(), OpCode::Data(Data::Text), true);
let view = format!("{}", f);
let view = format!("{f}");
assert!(view.contains("payload:"));
}
}
2 changes: 1 addition & 1 deletion src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl TryFrom<Message> for String {
impl fmt::Display for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> StdResult<(), fmt::Error> {
if let Ok(string) = self.to_text() {
write!(f, "{}", string)
write!(f, "{string}")
} else {
write!(f, "Binary Data<length={}>", self.len())
}
Expand Down

0 comments on commit 1617041

Please sign in to comment.