Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down
2 changes: 1 addition & 1 deletion src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
8 changes: 4 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}

Expand Down Expand Up @@ -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()
}
}

Expand All @@ -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) => {
Expand Down
10 changes: 4 additions & 6 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Parse {
pub(crate) fn new(frame: Frame) -> Result<Parse, ParseError> {
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 {
Expand Down Expand Up @@ -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()),
}
Expand All @@ -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()),
}
Expand All @@ -111,7 +109,7 @@ impl Parse {
// fails, an error is returned.
Frame::Simple(data) => atoi::<u64>(data.as_bytes()).ok_or_else(|| MSG.into()),
Frame::Bulk(data) => atoi::<u64>(&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()),
}
}

Expand Down