Skip to content

Commit 81888e3

Browse files
authored
fmt (#34)
1 parent ecf1eb4 commit 81888e3

File tree

13 files changed

+208
-75
lines changed

13 files changed

+208
-75
lines changed

examples/sub.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ pub async fn main() -> Result<()> {
2424
// Open a connection to the mini-redis address.
2525
let client = client::connect("127.0.0.1:6379").await?;
2626

27-
2827
// subscribe to channel foo
2928
let mut subscriber = client.subscribe(vec!["foo".into()]).await?;
3029

3130
// await messages on channel foo
3231
if let Some(msg) = subscriber.next_message().await? {
33-
println!("got message from the channel: {}; message = {:?}", msg.channel, msg.content);
32+
println!(
33+
"got message from the channel: {}; message = {:?}",
34+
msg.channel, msg.content
35+
);
3436
}
3537

3638
Ok(())

src/bin/cli.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum Command {
2424
/// Get the value of key.
2525
Get {
2626
/// Name of key to get
27-
key: String
27+
key: String,
2828
},
2929
/// Set key to hold the string value.
3030
Set {
@@ -76,11 +76,19 @@ async fn main() -> mini_redis::Result<()> {
7676
println!("(nil)");
7777
}
7878
}
79-
Command::Set { key, value, expires: None } => {
79+
Command::Set {
80+
key,
81+
value,
82+
expires: None,
83+
} => {
8084
client.set(&key, value).await?;
8185
println!("OK");
8286
}
83-
Command::Set { key, value, expires: Some(expires) } => {
87+
Command::Set {
88+
key,
89+
value,
90+
expires: Some(expires),
91+
} => {
8492
client.set_expires(&key, value, expires).await?;
8593
println!("OK");
8694
}

src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use crate::cmd::{Get, Publish, Set, Subscribe, Unsubscribe};
66
use crate::{Connection, Frame};
77

8+
use async_stream::try_stream;
89
use bytes::Bytes;
910
use std::io::{Error, ErrorKind};
1011
use std::time::Duration;
1112
use tokio::net::{TcpStream, ToSocketAddrs};
1213
use tokio::stream::Stream;
1314
use tracing::{debug, instrument};
14-
use async_stream::try_stream;
1515

1616
/// Established connection with a Redis server.
1717
///
@@ -416,7 +416,8 @@ impl Subscriber {
416416
self.client.subscribe_cmd(channels).await?;
417417

418418
// Update the set of subscribed channels.
419-
self.subscribed_channels.extend(channels.iter().map(Clone::clone));
419+
self.subscribed_channels
420+
.extend(channels.iter().map(Clone::clone));
420421

421422
Ok(())
422423
}
@@ -462,7 +463,7 @@ impl Subscriber {
462463
if self.subscribed_channels.len() != len - 1 {
463464
return Err(response.to_error());
464465
}
465-
},
466+
}
466467
_ => return Err(response.to_error()),
467468
},
468469
frame => return Err(frame.to_error()),

src/cmd/get.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub struct Get {
1717
impl Get {
1818
/// Create a new `Get` command which fetches `key`.
1919
pub(crate) fn new(key: impl ToString) -> Get {
20-
Get { key: key.to_string() }
20+
Get {
21+
key: key.to_string(),
22+
}
2123
}
2224

2325
/// Parse a `Get` instance from a received frame.

src/cmd/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) enum Command {
2525
Set(Set),
2626
Subscribe(Subscribe),
2727
Unsubscribe(Unsubscribe),
28-
Unknown(Unknown)
28+
Unknown(Unknown),
2929
}
3030

3131
impl Command {
@@ -66,7 +66,7 @@ impl Command {
6666
// the command is not recognized, there is most likely
6767
// unconsumed fields remaining in the `Parse` instance.
6868
return Ok(Command::Unknown(Unknown::new(command_name)));
69-
},
69+
}
7070
};
7171

7272
// Check if there is any remaining unconsumed fields in the `Parse`

src/cmd/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::{Connection, Db, Frame};
21
use crate::cmd::{Parse, ParseError};
2+
use crate::{Connection, Db, Frame};
33

44
use bytes::Bytes;
55
use std::time::Duration;

src/cmd/subscribe.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub struct Unsubscribe {
2727
impl Subscribe {
2828
/// Creates a new `Subscribe` command to listen on the specified channels.
2929
pub(crate) fn new(channels: &[String]) -> Subscribe {
30-
Subscribe { channels: channels.to_vec() }
30+
Subscribe {
31+
channels: channels.to_vec(),
32+
}
3133
}
3234

3335
/// Parse a `Subscribe` instance from a received frame.
@@ -221,7 +223,9 @@ impl Subscribe {
221223
impl Unsubscribe {
222224
/// Create a new `Unsubscribe` command with the given `channels`.
223225
pub(crate) fn new(channels: &[String]) -> Unsubscribe {
224-
Unsubscribe { channels: channels.to_vec() }
226+
Unsubscribe {
227+
channels: channels.to_vec(),
228+
}
225229
}
226230

227231
/// Parse a `Unsubscribe` instance from a received frame.

src/cmd/unknown.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ impl Unknown {
1212
/// Create a new `Unknown` command which responds to unknown commands
1313
/// issued by clients
1414
pub(crate) fn new(key: impl ToString) -> Unknown {
15-
Unknown { command_name: key.to_string() }
15+
Unknown {
16+
command_name: key.to_string(),
17+
}
1618
}
1719

1820
/// Returns the command name

src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Connection {
5454
/// # Returns
5555
///
5656
/// On success, the received frame is returned. If the `TcpStream`
57-
/// is closed in a way that doesn't break a frame in half, it retuns
57+
/// is closed in a way that doesn't break a frame in half, it retuns
5858
/// `None`. Otherwise, an error is returned.
5959
pub(crate) async fn read_frame(&mut self) -> crate::Result<Option<Frame>> {
6060
use frame::Error::Incomplete;

src/parse.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ impl Parse {
6767
Frame::Bulk(data) => str::from_utf8(&data[..])
6868
.map(|s| s.to_string())
6969
.map_err(|_| "protocol error; invalid string".into()),
70-
frame => Err(format!("protocol error; expected simple frame or bulk frame, got {:?}", frame).into()),
70+
frame => Err(format!(
71+
"protocol error; expected simple frame or bulk frame, got {:?}",
72+
frame
73+
)
74+
.into()),
7175
}
7276
}
7377

@@ -83,7 +87,11 @@ impl Parse {
8387
// raw bytes, they are considered separate types.
8488
Frame::Simple(s) => Ok(Bytes::from(s.into_bytes())),
8589
Frame::Bulk(data) => Ok(data),
86-
frame => Err(format!("protocol error; expected simple frame or bulk frame, got {:?}", frame).into()),
90+
frame => Err(format!(
91+
"protocol error; expected simple frame or bulk frame, got {:?}",
92+
frame
93+
)
94+
.into()),
8795
}
8896
}
8997

@@ -135,13 +143,10 @@ impl From<&str> for ParseError {
135143
impl fmt::Display for ParseError {
136144
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
137145
match self {
138-
ParseError::EndOfStream => {
139-
"protocol error; unexpected end of stream".fmt(f)
140-
}
146+
ParseError::EndOfStream => "protocol error; unexpected end of stream".fmt(f),
141147
ParseError::Other(err) => err.fmt(f),
142148
}
143149
}
144150
}
145151

146-
impl std::error::Error for ParseError {
147-
}
152+
impl std::error::Error for ParseError {}

0 commit comments

Comments
 (0)