implement client set (#11)

This commit is contained in:
Avery Harnish
2020-03-28 16:00:47 -05:00
committed by GitHub
parent fc5597f293
commit 7bd7086d41
16 changed files with 191 additions and 58 deletions

View File

@@ -6,7 +6,7 @@ use std::io::Cursor;
use std::num::TryFromIntError;
use std::string::FromUtf8Error;
#[derive(Debug)]
#[derive(Clone, Debug)]
pub(crate) enum Frame {
Simple(String),
Error(String),
@@ -148,6 +148,23 @@ impl Frame {
_ => unimplemented!(),
}
}
pub(crate) fn try_as_str(&self) -> Result<String, String> {
match &self {
Frame::Simple(response) => Ok(response.to_string()),
Frame::Error(response) => Err(response.to_string()),
Frame::Integer(response) => Ok(format!("{}", response)),
Frame::Bulk(response) => Ok(format!("{:?}", response)),
Frame::Null => Ok("(nil)".to_string()),
Frame::Array(response) => {
let mut msg = "".to_string();
for item in response {
msg.push_str(&item.try_as_str()?)
}
Ok(msg)
}
}
}
}
fn peek_u8(src: &mut Cursor<&[u8]>) -> Result<u8, Error> {