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

An integer.

A simple string.

An error.

A bulk string.

An array.

Methods

impl Value
[src]

[src]

Encodes a Value as a string.

Examples

use lib_resp::Value;

let error = Value::err("ERR");

assert_eq!(error.encode(), "-ERR\r\n");

[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");

[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());

[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());

[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);

[src]

Constructs a new simple string.

Examples

use lib_resp::Value;

let status = Value::str("OK");

println!("{:?}", status);

[src]

Constructs a new error.

Examples

use lib_resp::Value;

let err = Value::err("ERR");

println!("{:?}", err);

[src]

[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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for Value
[src]

impl PartialEq for Value
[src]

[src]

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

[src]

This method tests for !=.

impl Debug for Value
[src]

[src]

Formats the value using the given formatter. Read more

impl Display for Value
[src]

[src]

Formats the value using the given formatter. Read more

impl From<i64> for Value
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl Send for Value

impl Sync for Value