diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 1f175d6..3cbad4e 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -90,17 +90,17 @@ async fn main() -> mini_redis::Result<()> { Command::Ping { msg } => { let value = client.ping(msg).await?; if let Ok(string) = str::from_utf8(&value) { - println!("\"{}\"", string); + println!("\"{string}\""); } else { - println!("{:?}", value); + println!("{value:?}"); } } Command::Get { key } => { if let Some(value) = client.get(&key).await? { if let Ok(string) = str::from_utf8(&value) { - println!("\"{}\"", string); + println!("\"{string}\""); } else { - println!("{:?}", value); + println!("{value:?}"); } } else { println!("(nil)"); diff --git a/src/bin/server.rs b/src/bin/server.rs index 898b0a6..bed762d 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -36,7 +36,7 @@ pub async fn main() -> mini_redis::Result<()> { let port = cli.port.unwrap_or(DEFAULT_PORT); // Bind a TCP listener - let listener = TcpListener::bind(&format!("127.0.0.1:{}", port)).await?; + let listener = TcpListener::bind(&format!("127.0.0.1:{port}")).await?; server::run(listener, signal::ctrl_c()).await; diff --git a/src/connection.rs b/src/connection.rs index 64c11c8..26769c4 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -225,7 +225,7 @@ impl Connection { // Convert the value to a string let mut buf = [0u8; 20]; let mut buf = Cursor::new(&mut buf[..]); - write!(&mut buf, "{}", val)?; + write!(&mut buf, "{val}")?; let pos = buf.position() as usize; self.stream.write_all(&buf.get_ref()[..pos]).await?; diff --git a/src/frame.rs b/src/frame.rs index ab41029..bb30a1f 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -98,7 +98,7 @@ impl Frame { Ok(()) } - actual => Err(format!("protocol error; invalid frame type byte `{}`", actual).into()), + actual => Err(format!("protocol error; invalid frame type byte `{actual}`").into()), } } @@ -169,7 +169,7 @@ impl Frame { /// Converts the frame to an "unexpected frame" error pub(crate) fn to_error(&self) -> crate::Error { - format!("unexpected frame: {}", self).into() + format!("unexpected frame: {self}").into() } } @@ -189,11 +189,11 @@ impl fmt::Display for Frame { match self { Frame::Simple(response) => response.fmt(fmt), - Frame::Error(msg) => write!(fmt, "error: {}", msg), + Frame::Error(msg) => write!(fmt, "error: {msg}"), Frame::Integer(num) => num.fmt(fmt), Frame::Bulk(msg) => match str::from_utf8(msg) { Ok(string) => string.fmt(fmt), - Err(_) => write!(fmt, "{:?}", msg), + Err(_) => write!(fmt, "{msg:?}"), }, Frame::Null => "(nil)".fmt(fmt), Frame::Array(parts) => { diff --git a/src/parse.rs b/src/parse.rs index f2a73b5..4bb198c 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -36,7 +36,7 @@ impl Parse { pub(crate) fn new(frame: Frame) -> Result { let array = match frame { Frame::Array(array) => array, - frame => return Err(format!("protocol error; expected array, got {:?}", frame).into()), + frame => return Err(format!("protocol error; expected array, got {frame:?}").into()), }; Ok(Parse { @@ -65,8 +65,7 @@ impl Parse { .map(|s| s.to_string()) .map_err(|_| "protocol error; invalid string".into()), frame => Err(format!( - "protocol error; expected simple frame or bulk frame, got {:?}", - frame + "protocol error; expected simple frame or bulk frame, got {frame:?}" ) .into()), } @@ -85,8 +84,7 @@ impl Parse { Frame::Simple(s) => Ok(Bytes::from(s.into_bytes())), Frame::Bulk(data) => Ok(data), frame => Err(format!( - "protocol error; expected simple frame or bulk frame, got {:?}", - frame + "protocol error; expected simple frame or bulk frame, got {frame:?}" ) .into()), } @@ -111,7 +109,7 @@ impl Parse { // fails, an error is returned. Frame::Simple(data) => atoi::(data.as_bytes()).ok_or_else(|| MSG.into()), Frame::Bulk(data) => atoi::(&data).ok_or_else(|| MSG.into()), - frame => Err(format!("protocol error; expected int frame but got {:?}", frame).into()), + frame => Err(format!("protocol error; expected int frame but got {frame:?}").into()), } }