Skip to content

Commit 9852de9

Browse files
runs cargofmt (#3)
1 parent 358e95e commit 9852de9

File tree

11 files changed

+31
-32
lines changed

11 files changed

+31
-32
lines changed

examples/chat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#[tokio::main]
32
async fn main() {
43
unimplemented!();

examples/hello_world.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

examples/pub.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use crate::Connection;
33

44
use bytes::Bytes;
5-
use tokio::net::{TcpStream, ToSocketAddrs};
65
use std::io;
6+
use tokio::net::{TcpStream, ToSocketAddrs};
77

88
/// Mini asynchronous Redis client
99
pub struct Client {

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, Frame, Kv};
21
use crate::cmd::{Parse, ParseError};
2+
use crate::{Connection, Frame, Kv};
33

44
use bytes::Bytes;
55
use std::io;

src/cmd/subscribe.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{Command, Connection, Frame, Kv, Shutdown};
21
use crate::cmd::{Parse, ParseError};
2+
use crate::{Command, Connection, Frame, Kv, Shutdown};
33

44
use bytes::Bytes;
5-
use tokio::select;
6-
use tokio::stream::{StreamMap, StreamExt};
75
use std::io;
6+
use tokio::select;
7+
use tokio::stream::{StreamExt, StreamMap};
88

99
#[derive(Debug)]
1010
pub struct Subscribe {
@@ -49,7 +49,6 @@ impl Subscribe {
4949
dst: &mut Connection,
5050
shutdown: &mut Shutdown,
5151
) -> io::Result<()> {
52-
5352
// Each individual channel subscription is handled using a
5453
// `sync::broadcast` channel. Messages are then fanned out to all
5554
// clients currently subscribed to the channels.

src/conn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::frame::{self, Frame};
22

33
use bytes::{Buf, BytesMut};
4-
use tokio::io::{BufStream, AsyncReadExt, AsyncWriteExt};
5-
use tokio::net::TcpStream;
64
use std::io::{self, Cursor};
5+
use tokio::io::{AsyncReadExt, AsyncWriteExt, BufStream};
6+
use tokio::net::TcpStream;
77

88
#[derive(Debug)]
99
pub(crate) struct Connection {

src/frame.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Frame {
7474
b'*' => {
7575
let len = get_decimal(src)?;
7676

77-
for _ in 0.. len {
77+
for _ in 0..len {
7878
Frame::check(src)?;
7979
}
8080

@@ -139,7 +139,7 @@ impl Frame {
139139
let len = get_decimal(src)?.try_into()?;
140140
let mut out = Vec::with_capacity(len);
141141

142-
for _ in 0.. len {
142+
for _ in 0..len {
143143
out.push(Box::new(Frame::parse(src)?));
144144
}
145145

@@ -181,8 +181,7 @@ fn get_decimal(src: &mut Cursor<&[u8]>) -> Result<u64, Error> {
181181

182182
let line = get_line(src)?;
183183

184-
atoi::<u64>(line)
185-
.ok_or(Error::Invalid)
184+
atoi::<u64>(line).ok_or(Error::Invalid)
186185
}
187186

188187
/// Find a line
@@ -193,7 +192,7 @@ fn get_line<'a>(src: &mut Cursor<&'a [u8]>) -> Result<&'a [u8], Error> {
193192
let end = src.get_ref().len() - 1;
194193

195194
for i in start..end {
196-
if src.get_ref()[i] == b'\r' && src.get_ref()[i+1] == b'\n' {
195+
if src.get_ref()[i] == b'\r' && src.get_ref()[i + 1] == b'\n' {
197196
// We found a line, update the position to be *after* the \n
198197
src.set_position((i + 2) as u64);
199198

src/kv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use bytes::Bytes;
2-
use tokio::sync::broadcast;
32
use std::collections::HashMap;
43
use std::sync::{Arc, Mutex};
54
use std::time::Duration;
5+
use tokio::sync::broadcast;
66

77
#[derive(Debug, Clone)]
88
pub(crate) struct Kv {
@@ -44,9 +44,7 @@ impl Kv {
4444
let mut shared = self.shared.lock().unwrap();
4545

4646
match shared.pub_sub.entry(key) {
47-
Entry::Occupied(e) => {
48-
e.get().subscribe()
49-
}
47+
Entry::Occupied(e) => e.get().subscribe(),
5048
Entry::Vacant(e) => {
5149
let (tx, rx) = broadcast::channel(1028);
5250
e.insert(tx);
@@ -58,7 +56,9 @@ impl Kv {
5856
pub(crate) fn publish(&self, key: &str, value: Bytes) -> usize {
5957
let shared = self.shared.lock().unwrap();
6058

61-
shared.pub_sub.get(key)
59+
shared
60+
.pub_sub
61+
.get(key)
6262
.map(|tx| tx.send(value).unwrap_or(0))
6363
.unwrap_or(0)
6464
}

src/parse.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,24 @@ impl Parse {
2323
_ => return Err(ParseError::Invalid),
2424
};
2525

26-
Ok(Parse { parts: array.into_iter() })
26+
Ok(Parse {
27+
parts: array.into_iter(),
28+
})
2729
}
2830

2931
fn next(&mut self) -> Result<Frame, ParseError> {
30-
self.parts.next()
32+
self.parts
33+
.next()
3134
.map(|frame| *frame)
3235
.ok_or(ParseError::EndOfStream)
3336
}
3437

3538
pub(crate) fn next_string(&mut self) -> Result<String, ParseError> {
3639
match self.next()? {
3740
Frame::Simple(s) => Ok(s),
38-
Frame::Bulk(data) => {
39-
str::from_utf8(&data[..])
40-
.map(|s| s.to_string())
41-
.map_err(|_| ParseError::Invalid)
42-
}
41+
Frame::Bulk(data) => str::from_utf8(&data[..])
42+
.map(|s| s.to_string())
43+
.map_err(|_| ParseError::Invalid),
4344
_ => Err(ParseError::Invalid),
4445
}
4546
}
@@ -79,6 +80,7 @@ impl From<ParseError> for io::Error {
7980
EndOfStream => "end of stream".to_string(),
8081
Invalid => "invalid".to_string(),
8182
UnknownCommand(cmd) => format!("unknown command `{}`", cmd),
82-
})
83+
},
84+
)
8385
}
8486
}

0 commit comments

Comments
 (0)