make more APIs public (#55)

This commit is contained in:
Carl Lerche
2020-06-12 15:15:51 -07:00
committed by GitHub
parent f1042d6b7c
commit 03f8281431
7 changed files with 18 additions and 17 deletions

View File

@@ -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
}

View File

@@ -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<Command> {
pub fn from_frame(frame: Frame) -> crate::Result<Command> {
// The frame value is decorated with `Parse`. `Parse` provides a
// "cursor" like API which makes parsing the command easier.
//

View File

@@ -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<Duration>) -> Set {
pub fn new(key: impl ToString, value: Bytes, expire: Option<Duration>) -> 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

View File

@@ -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<Option<Frame>> {
pub async fn read_frame(&mut self) -> crate::Result<Option<Frame>> {
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.

View File

@@ -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),

View File

@@ -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;

View File

@@ -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,