Enum lib_resp::Value
[−]
[src]
pub enum Value {
Int(i64),
Str(String),
Err(String),
BStr(Option<String>),
Array(Option<Vec<Value>>),
}In-memory representation of a RESP value.
Variants
Int(i64)An integer.
Str(String)A simple string.
Err(String)An error.
BStr(Option<String>)A bulk string.
Array(Option<Vec<Value>>)An array.
Methods
impl Value[src]
pub fn encode(&self) -> String[src]
Encodes a Value as a string.
Examples
use lib_resp::Value; let error = Value::err("ERR"); assert_eq!(error.encode(), "-ERR\r\n");
pub fn encode_bytes(&self) -> Vec<u8>[src]
Encodes a Value as a vector of bytes.
Examples
use lib_resp::Value; let error = Value::err("ERR"); assert_eq!(&error.encode_bytes(), b"-ERR\r\n");
pub fn is_null(&self) -> bool[src]
Checks if a Value is null.
NOTE: Only the Array and BStr types can represent a null value.
Examples
use lib_resp::Value; let name = Value::BStr(None); assert!(name.is_null());
use lib_resp::Value; let name = Value::b_str(Some("Josh")); assert!(!name.is_null());
pub fn is_empty(&self) -> bool[src]
Checks is a Value is empty.
Examples
use lib_resp::Value; let error = Value::err(""); assert!(error.is_empty());
use lib_resp::Value; let error = Value::err("ERR"); assert!(!error.is_empty())
Null values count as empty too:
use lib_resp::Value; let name = Value::BStr(None); assert!(name.is_empty());
pub fn int(value: i64) -> Self[src]
Constructs a new integer value.
NOTE: Using this function has no benefits, it's simply here for completeness.
Examples
use lib_resp::Value; let age = Value::int(-3); println!("{:?}", age);
pub fn str<T>(value: T) -> Self where
T: ToString, [src]
T: ToString,
Constructs a new simple string.
Examples
use lib_resp::Value; let status = Value::str("OK"); println!("{:?}", status);
pub fn err<T>(error: T) -> Self where
T: ToString, [src]
T: ToString,
Constructs a new error.
Examples
use lib_resp::Value; let err = Value::err("ERR"); println!("{:?}", err);
pub fn b_str<T>(value: Option<T>) -> Self where
T: ToString, [src]
T: ToString,
pub fn array(values: Option<Vec<Value>>) -> Self[src]
Constructs a new array value.
NOTE: Using this function has no benefits, it's simply here for completeness.
Examples
use lib_resp::Value; let users = Value::array(Some(vec![ Value::b_str(Some("foo")), Value::b_str(Some("bar")), Value::b_str(Some("baz")) ])); println!("{:?}", users);
Trait Implementations
impl Clone for Value[src]
fn clone(&self) -> Value[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Eq for Value[src]
impl PartialEq for Value[src]
fn eq(&self, __arg_0: &Value) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Value) -> bool[src]
This method tests for !=.
impl Debug for Value[src]
fn fmt(&self, f: &mut Formatter) -> FmtResult[src]
Formats the value using the given formatter. Read more
impl Display for Value[src]
fn fmt(&self, f: &mut Formatter) -> FmtResult[src]
Formats the value using the given formatter. Read more