Enum resp::Value [] [src]

pub enum Value {
    Null,
    NullArray,
    String(String),
    Error(String),
    Integer(i64),
    Bulk(String),
    BufBulk(Vec<u8>),
    Array(Vec<Value>),
}

Represents a RESP value, see Redis Protocol specification.

Variants

Null bulk reply, $-1\r\n

Null array reply, *-1\r\n

For Simple Strings the first byte of the reply is "+".

For Errors the first byte of the reply is "-".

For Integers the first byte of the reply is ":".

For Bulk Strings the first byte of the reply is "$".

For Bulk Strings the first byte of the reply is "$".

For Arrays the first byte of the reply is "*".

Methods

impl Value
[src]

Returns true if the value is a Null or NullArray. Returns false otherwise.

Examples

assert_eq!(Value::Null.is_null(), true);
assert_eq!(Value::NullArray.is_null(), true);
assert_eq!(Value::Integer(123).is_null(), false);Run

Returns true if the value is a Error. Returns false otherwise.

Examples

assert_eq!(Value::Null.is_error(), false);
assert_eq!(Value::Error("".to_string()).is_error(), true);Run

Encode the value to RESP binary buffer.

Examples

let val = Value::String("OK正".to_string());
assert_eq!(val.encode(), vec![43, 79, 75, 230, 173, 163, 13, 10]);Run

Encode the value to RESP string.

Examples

let val = Value::String("OK正".to_string());
assert_eq!(val.to_encoded_string().unwrap(), "+OK正\r\n");Run

Encode the value to beautify formated string.

Examples

assert_eq!(Value::Null.to_string_pretty(), "(Null)");
assert_eq!(Value::NullArray.to_string_pretty(), "(Null Array)");
assert_eq!(Value::String("OK".to_string()).to_string_pretty(), "OK");
assert_eq!(Value::Error("Err".to_string()).to_string_pretty(), "(Error) Err");
assert_eq!(Value::Integer(123).to_string_pretty(), "(Integer) 123");
assert_eq!(Value::Bulk("Bulk String".to_string()).to_string_pretty(), "\"Bulk String\"");
assert_eq!(Value::BufBulk(vec![]).to_string_pretty(), "(Empty Buffer)");
assert_eq!(Value::BufBulk(vec![0, 100]).to_string_pretty(), "(Buffer) 00 64");
assert_eq!(Value::Array(vec![]).to_string_pretty(), "(Empty Array)");Run

A full formated example:

 1) (Null)
 2) (Null Array)
 3) OK
 4) (Error) Err
 5) (Integer) 123
 6) \"Bulk String\"
 7) (Empty Array)
 8) (Buffer) 00 64
 9) 1) (Empty Array)
    2) (Integer) 123
    3) \"Bulk String\"
10) 1) (Null)
    2) (Null Array)
    3) OK
    4) (Error) Err
    5) (Integer) 123
    6) \"Bulk String\"
    7) (Empty Array)
    8) (Buffer) 00 64
    9) 1) (Empty Array)
       2) (Integer) 123
       3) \"Bulk String\"
11) (Null)
12) 1) (Null)
    2) (Null Array)
    3) OK
    4) (Error) Err
    5) (Integer) 123
    6) \"Bulk String\"
    7) (Empty Array)
    8) (Buffer) 00 64
    9) 1) (Empty Array)
       2) (Integer) 123
       3) \"Bulk String\"
   10) 1) (Null)
       2) (Null Array)
       3) OK
       4) (Error) Err
       5) (Integer) 123
       6) \"Bulk String\"
       7) (Empty Array)
       8) (Buffer) 00 64
       9) 1) (Empty Array)
          2) (Integer) 123
          3) \"Bulk String\"
   11) (Null)
13) (Null)

[DEPRECATED] Alias of to_string_pretty.

Trait Implementations

impl Clone for Value
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for Value
[src]

impl PartialEq for Value
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Value
[src]

Formats the value using the given formatter.

impl Sync for Value
[src]

impl Send for Value
[src]