Skip to content

Commit 03f8281

Browse files
authored
make more APIs public (#55)
1 parent f1042d6 commit 03f8281

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/cmd/get.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ pub struct Get {
1616

1717
impl Get {
1818
/// Create a new `Get` command which fetches `key`.
19-
pub(crate) fn new(key: impl ToString) -> Get {
19+
pub fn new(key: impl ToString) -> Get {
2020
Get {
2121
key: key.to_string(),
2222
}
2323
}
2424

2525
/// Get the key
26-
pub(crate) fn key(&self) -> &str {
26+
pub fn key(&self) -> &str {
2727
&self.key
2828
}
2929

src/cmd/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{Connection, Db, Frame, Parse, ParseError, Shutdown};
1919
///
2020
/// Methods called on `Command` are delegated to the command implementation.
2121
#[derive(Debug)]
22-
pub(crate) enum Command {
22+
pub enum Command {
2323
Get(Get),
2424
Publish(Publish),
2525
Set(Set),
@@ -37,7 +37,7 @@ impl Command {
3737
/// # Returns
3838
///
3939
/// On success, the command value is returned, otherwise, `Err` is returned.
40-
pub(crate) fn from_frame(frame: Frame) -> crate::Result<Command> {
40+
pub fn from_frame(frame: Frame) -> crate::Result<Command> {
4141
// The frame value is decorated with `Parse`. `Parse` provides a
4242
// "cursor" like API which makes parsing the command easier.
4343
//

src/cmd/set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Set {
3434
///
3535
/// If `expire` is `Some`, the value should expire after the specified
3636
/// duration.
37-
pub(crate) fn new(key: impl ToString, value: Bytes, expire: Option<Duration>) -> Set {
37+
pub fn new(key: impl ToString, value: Bytes, expire: Option<Duration>) -> Set {
3838
Set {
3939
key: key.to_string(),
4040
value,
@@ -43,13 +43,13 @@ impl Set {
4343
}
4444

4545
/// Get the key
46-
pub(crate) fn key(&self) -> &str {
46+
pub fn key(&self) -> &str {
4747
&self.key
4848
}
4949

5050
/// Get the value
51-
pub(crate) fn value(&self) -> Bytes {
52-
self.value.clone()
51+
pub fn value(&self) -> &Bytes {
52+
&self.value
5353
}
5454

5555
/// Get the expires

src/connection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tokio::net::TcpStream;
1818
/// When sending frames, the frame is first encoded into the write buffer.
1919
/// The contents of the write buffer are then written to the socket.
2020
#[derive(Debug)]
21-
pub(crate) struct Connection {
21+
pub struct Connection {
2222
// The `TcpStream`. It is decorated with a `BufWriter`, which provides write
2323
// level buffering. The `BufWriter` implementation provided by Tokio is
2424
// sufficient for our needs.
@@ -34,7 +34,7 @@ pub(crate) struct Connection {
3434
impl Connection {
3535
/// Create a new `Connection`, backed by `socket`. Read and write buffers
3636
/// are initialized.
37-
pub(crate) fn new(socket: TcpStream) -> Connection {
37+
pub fn new(socket: TcpStream) -> Connection {
3838
Connection {
3939
stream: BufWriter::new(socket),
4040
// Default to a 4KB read buffer. For the use case of mini redis,
@@ -56,7 +56,7 @@ impl Connection {
5656
/// On success, the received frame is returned. If the `TcpStream`
5757
/// is closed in a way that doesn't break a frame in half, it returns
5858
/// `None`. Otherwise, an error is returned.
59-
pub(crate) async fn read_frame(&mut self) -> crate::Result<Option<Frame>> {
59+
pub async fn read_frame(&mut self) -> crate::Result<Option<Frame>> {
6060
use frame::Error::Incomplete;
6161

6262
loop {
@@ -146,7 +146,7 @@ impl Connection {
146146
/// syscalls. However, it is fine to call these functions on a *buffered*
147147
/// write stream. The data will be written to the buffer. Once the buffer is
148148
/// full, it is flushed to the underlying socket.
149-
pub(crate) async fn write_frame(&mut self, frame: &Frame) -> io::Result<()> {
149+
pub async fn write_frame(&mut self, frame: &Frame) -> io::Result<()> {
150150
// Arrays are encoded by encoding each entry. All other frame types are
151151
// considered literals. For now, mini-redis is not able to encode
152152
// recursive frame structures. See below for more details.

src/frame.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use std::io::Cursor;
55
use std::num::TryFromIntError;
66
use std::string::FromUtf8Error;
77

8+
/// A frame in the Redis protocol.
89
#[derive(Clone, Debug)]
9-
pub(crate) enum Frame {
10+
pub enum Frame {
1011
Simple(String),
1112
Error(String),
1213
Integer(u64),

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
pub mod client;
2929

3030
pub mod cmd;
31-
use cmd::Command;
31+
pub use cmd::Command;
3232

3333
mod connection;
34-
use connection::Connection;
34+
pub use connection::Connection;
3535

3636
mod frame;
37-
use frame::Frame;
37+
pub use frame::Frame;
3838

3939
mod db;
4040
use db::Db;

src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn run(
3333
}
3434
Command::Set(set) => {
3535
let key = set.key();
36-
let value = set.value();
36+
let value = set.value().clone();
3737
let expires = set.expire();
3838
let result = match expires {
3939
None => client.set(&key, value).await,

0 commit comments

Comments
 (0)