diff --git a/src/cmd/get.rs b/src/cmd/get.rs index 4ee50a0..81964a8 100644 --- a/src/cmd/get.rs +++ b/src/cmd/get.rs @@ -16,14 +16,14 @@ pub struct Get { impl Get { /// Create a new `Get` command which fetches `key`. - pub(crate) fn new(key: impl ToString) -> Get { + pub fn new(key: impl ToString) -> Get { Get { key: key.to_string(), } } /// Get the key - pub(crate) fn key(&self) -> &str { + pub fn key(&self) -> &str { &self.key } diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 7a98831..2da5ad0 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -19,7 +19,7 @@ use crate::{Connection, Db, Frame, Parse, ParseError, Shutdown}; /// /// Methods called on `Command` are delegated to the command implementation. #[derive(Debug)] -pub(crate) enum Command { +pub enum Command { Get(Get), Publish(Publish), Set(Set), @@ -37,7 +37,7 @@ impl Command { /// # Returns /// /// On success, the command value is returned, otherwise, `Err` is returned. - pub(crate) fn from_frame(frame: Frame) -> crate::Result { + pub fn from_frame(frame: Frame) -> crate::Result { // The frame value is decorated with `Parse`. `Parse` provides a // "cursor" like API which makes parsing the command easier. // diff --git a/src/cmd/set.rs b/src/cmd/set.rs index 1d10b33..25884dc 100644 --- a/src/cmd/set.rs +++ b/src/cmd/set.rs @@ -34,7 +34,7 @@ impl Set { /// /// If `expire` is `Some`, the value should expire after the specified /// duration. - pub(crate) fn new(key: impl ToString, value: Bytes, expire: Option) -> Set { + pub fn new(key: impl ToString, value: Bytes, expire: Option) -> Set { Set { key: key.to_string(), value, @@ -43,13 +43,13 @@ impl Set { } /// Get the key - pub(crate) fn key(&self) -> &str { + pub fn key(&self) -> &str { &self.key } /// Get the value - pub(crate) fn value(&self) -> Bytes { - self.value.clone() + pub fn value(&self) -> &Bytes { + &self.value } /// Get the expires diff --git a/src/connection.rs b/src/connection.rs index c6ea322..19a7274 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -18,7 +18,7 @@ use tokio::net::TcpStream; /// When sending frames, the frame is first encoded into the write buffer. /// The contents of the write buffer are then written to the socket. #[derive(Debug)] -pub(crate) struct Connection { +pub struct Connection { // The `TcpStream`. It is decorated with a `BufWriter`, which provides write // level buffering. The `BufWriter` implementation provided by Tokio is // sufficient for our needs. @@ -34,7 +34,7 @@ pub(crate) struct Connection { impl Connection { /// Create a new `Connection`, backed by `socket`. Read and write buffers /// are initialized. - pub(crate) fn new(socket: TcpStream) -> Connection { + pub fn new(socket: TcpStream) -> Connection { Connection { stream: BufWriter::new(socket), // Default to a 4KB read buffer. For the use case of mini redis, @@ -56,7 +56,7 @@ impl Connection { /// On success, the received frame is returned. If the `TcpStream` /// is closed in a way that doesn't break a frame in half, it returns /// `None`. Otherwise, an error is returned. - pub(crate) async fn read_frame(&mut self) -> crate::Result> { + pub async fn read_frame(&mut self) -> crate::Result> { use frame::Error::Incomplete; loop { @@ -146,7 +146,7 @@ impl Connection { /// syscalls. However, it is fine to call these functions on a *buffered* /// write stream. The data will be written to the buffer. Once the buffer is /// full, it is flushed to the underlying socket. - pub(crate) async fn write_frame(&mut self, frame: &Frame) -> io::Result<()> { + pub async fn write_frame(&mut self, frame: &Frame) -> io::Result<()> { // Arrays are encoded by encoding each entry. All other frame types are // considered literals. For now, mini-redis is not able to encode // recursive frame structures. See below for more details. diff --git a/src/frame.rs b/src/frame.rs index 473f43e..d562e34 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -5,8 +5,9 @@ use std::io::Cursor; use std::num::TryFromIntError; use std::string::FromUtf8Error; +/// A frame in the Redis protocol. #[derive(Clone, Debug)] -pub(crate) enum Frame { +pub enum Frame { Simple(String), Error(String), Integer(u64), diff --git a/src/lib.rs b/src/lib.rs index 1e2ae71..9421079 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,13 +28,13 @@ pub mod client; pub mod cmd; -use cmd::Command; +pub use cmd::Command; mod connection; -use connection::Connection; +pub use connection::Connection; mod frame; -use frame::Frame; +pub use frame::Frame; mod db; use db::Db; diff --git a/src/pool.rs b/src/pool.rs index 673368c..c8ea31a 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -33,7 +33,7 @@ async fn run( } Command::Set(set) => { let key = set.key(); - let value = set.value(); + let value = set.value().clone(); let expires = set.expire(); let result = match expires { None => client.set(&key, value).await,