Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Deeds67 committed Mar 10, 2024
1 parent ce06426 commit ca78017
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod respparser;
mod server;
mod respserializer;
mod server;

fn main() {
let port: &str = "6388";
Expand Down
4 changes: 1 addition & 3 deletions src/respparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ impl<R: BufRead> RespParser<R> {
}
}



#[cfg(test)]
mod resp_parser_tests {
use super::*;
Expand Down Expand Up @@ -162,7 +160,7 @@ mod resp_parser_tests {
x => panic!("Unexpected RESP type: {:?}", x),
}
}

#[test]
fn test_parse_null() {
let data = "*-1\r\n";
Expand Down
16 changes: 7 additions & 9 deletions src/respserializer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::respparser::RespType;


#[derive(Debug, PartialEq)]
pub struct RespSerializer<W: std::io::Write> {
writer: W,
Expand All @@ -15,33 +14,32 @@ impl<W: std::io::Write> RespSerializer<W> {
match resp {
RespType::SimpleString(s) => {
writeln!(self.writer, "+{}\r", s)
},
}
RespType::Error(s) => {
writeln!(self.writer, "-{}\r", s)
},
}
RespType::Integer(i) => {
writeln!(self.writer, ":{}\r", i)
},
}
RespType::BulkString(bytes) => {
writeln!(self.writer, "${}\r", bytes.len())?;
self.writer.write_all(bytes)?;
writeln!(self.writer, "\r")
},
}
RespType::Array(arr) => {
writeln!(self.writer, "*{}\r", arr.len())?;
for resp in arr {
self.serialize(resp)?;
}
Ok(())
},
}
RespType::Null => {
writeln!(self.writer, "$-1\r")
},
}
}
}
}


#[cfg(test)]
mod resp_serializer_tests {
use super::*;
Expand Down Expand Up @@ -103,4 +101,4 @@ mod resp_serializer_tests {
serializer.serialize(&resp).unwrap();
assert_eq!(writer, b"$-1\r\n");
}
}
}
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn handle_client(mut stream: TcpStream) {
let mut serializer = RespSerializer::new(stream);
let _ = serializer.serialize(&mock_response);
}

pub fn start_tcp_stream(port: &str) {
let listener = TcpListener::bind(format!("127.0.0.1:{}", port)).expect("Could not bind");
for stream in listener.incoming() {
Expand Down

0 comments on commit ca78017

Please sign in to comment.