Enum rmp::value::Value [] [src]

pub enum Value {
    Nil,
    Boolean(bool),
    Integer(Integer),
    Float(Float),
    String(String),
    Binary(Vec<u8>),
    Array(Vec<Value>),
    Map(Vec<(Value, Value)>),
    Ext(i8Vec<u8>),
}

Variants

Nil

Nil represents nil.

Boolean(bool)

Boolean represents true or false.

Integer(Integer)

Integer represents an integer.

Float(Float)

Float represents a floating point number.

String(String)

String extending Raw type represents a UTF-8 string.

Binary(Vec<u8>)

Binary extending Raw type represents a byte array.

Array(Vec<Value>)

Array represents a sequence of objects.

Map(Vec<(Value, Value)>)

Map represents key-value pairs of objects.

Ext(i8Vec<u8>)

Extended implements Extension interface: represents a tuple of type information and a byte array where type information is an integer whose meaning is defined by applications.

Methods

impl Value
[src]

fn is_nil(&self) -> bool

Returns true if the Value is a Null. Returns false otherwise.

Examples

use rmp::Value;

assert!(Value::Nil.is_nil());

fn is_bool(&self) -> bool

Returns true if the Value is a Boolean. Returns false otherwise.

Examples

use rmp::Value;

assert!(Value::Boolean(true).is_bool());

assert!(!Value::Nil.is_bool());

fn is_i64(&self) -> bool

Returns true if (and only if) the Value is a i64. Returns false otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert!(Value::Integer(Integer::I64(42)).is_i64());

assert!(!Value::Integer(Integer::U64(42)).is_i64());
assert!(!Value::Float(Float::F32(42.0)).is_i64());
assert!(!Value::Float(Float::F64(42.0)).is_i64());

fn is_u64(&self) -> bool

Returns true if (and only if) the Value is a u64. Returns false otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert!(Value::Integer(Integer::U64(42)).is_u64());

assert!(!Value::Integer(Integer::I64(42)).is_u64());
assert!(!Value::Float(Float::F32(42.0)).is_u64());
assert!(!Value::Float(Float::F64(42.0)).is_u64());

fn is_f32(&self) -> bool

Returns true if (and only if) the Value is a f32. Returns false otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert!(Value::Float(Float::F32(42.0)).is_f32());

assert!(!Value::Integer(Integer::I64(42)).is_f32());
assert!(!Value::Integer(Integer::U64(42)).is_f32());
assert!(!Value::Float(Float::F64(42.0)).is_f32());

fn is_f64(&self) -> bool

Returns true if (and only if) the Value is a f64. Returns false otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert!(Value::Float(Float::F64(42.0)).is_f64());

assert!(!Value::Integer(Integer::I64(42)).is_f64());
assert!(!Value::Integer(Integer::U64(42)).is_f64());
assert!(!Value::Float(Float::F32(42.0)).is_f64());

fn is_number(&self) -> bool

Returns true if the Value is a Number. Returns false otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert!(Value::Integer(Integer::I64(42)).is_number());
assert!(Value::Integer(Integer::U64(42)).is_number());
assert!(Value::Float(Float::F32(42.0)).is_number());
assert!(Value::Float(Float::F64(42.0)).is_number());

assert!(!Value::Nil.is_number());

fn is_str(&self) -> bool

Returns true if the Value is a String. Returns false otherwise.

Examples

use rmp::Value;

assert!(Value::String("value".into()).is_str());

assert!(!Value::Nil.is_str());

fn is_bin(&self) -> bool

Returns true if the Value is a Binary. Returns false otherwise.

fn is_array(&self) -> bool

Returns true if the Value is an Array. Returns false otherwise.

fn is_map(&self) -> bool

Returns true if the Value is a Map. Returns false otherwise.

fn is_ext(&self) -> bool

Returns true if the Value is an Ext. Returns false otherwise.

fn as_bool(&self) -> Option<bool>

If the Value is a Boolean, returns the associated bool. Returns None otherwise.

Examples

use rmp::Value;

assert_eq!(Some(true), Value::Boolean(true).as_bool());

assert_eq!(None, Value::Nil.as_bool());

fn as_i64(&self) -> Option<i64>

If the Value is an integer, return or cast it to a i64. Returns None otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert_eq!(Some(42i64), Value::Integer(Integer::I64(42)).as_i64());
assert_eq!(Some(42i64), Value::Integer(Integer::U64(42)).as_i64());

assert_eq!(None, Value::Float(Float::F64(42.0)).as_i64());

fn as_u64(&self) -> Option<u64>

If the Value is an integer, return or cast it to a u64. Returns None otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert_eq!(Some(42u64), Value::Integer(Integer::I64(42)).as_u64());
assert_eq!(Some(42u64), Value::Integer(Integer::U64(42)).as_u64());

assert_eq!(None, Value::Integer(Integer::I64(-42)).as_u64());
assert_eq!(None, Value::Float(Float::F64(42.0)).as_u64());

fn as_f64(&self) -> Option<f64>

If the Value is a number, return or cast it to a f64. Returns None otherwise.

Examples

use rmp::Value;
use rmp::value::{Float, Integer};

assert_eq!(Some(42.0), Value::Integer(Integer::I64(42)).as_f64());
assert_eq!(Some(42.0), Value::Integer(Integer::U64(42)).as_f64());
assert_eq!(Some(42.0), Value::Float(Float::F32(42.0f32)).as_f64());
assert_eq!(Some(42.0), Value::Float(Float::F64(42.0f64)).as_f64());

assert_eq!(Some(2147483647.0), Value::Integer(Integer::I64(i32::max_value() as i64)).as_f64());

assert_eq!(None, Value::Nil.as_f64());

assert_eq!(None, Value::Integer(Integer::I64(i32::max_value() as i64 + 1)).as_f64());

fn as_str(&self) -> Option<&str>

If the Value is a String, returns the associated str. Returns None otherwise.

Examples

use rmp::Value;

assert_eq!(Some("le message"), Value::String("le message".into()).as_str());

assert_eq!(None, Value::Boolean(true).as_str());

fn as_slice(&self) -> Option<&[u8]>

If the Value is a Binary, returns the associated slice. Returns None otherwise.

Examples

use rmp::Value;

assert_eq!(Some(&[1, 2, 3, 4, 5][..]), Value::Binary(vec![1, 2, 3, 4, 5]).as_slice());

assert_eq!(None, Value::Boolean(true).as_slice());

fn as_array(&self) -> Option<&Vec<Value>>

If the Value is an Array, returns the associated vector. Returns None otherwise.

Examples

use rmp::Value;

let val = Value::Array(vec![Value::Nil, Value::Boolean(true)]);

assert_eq!(Some(&vec![Value::Nil, Value::Boolean(true)]), val.as_array());

assert_eq!(None, Value::Nil.as_array());

fn as_map(&self) -> Option<&Vec<(Value, Value)>>

If the Value is a Map, returns the associated vector of key-value tuples. Returns None otherwise.

Note

MessagePack represents map as a vector of key-value tuples.

Examples

use rmp::Value;

let val = Value::Map(vec![(Value::Nil, Value::Boolean(true))]);

assert_eq!(Some(&vec![(Value::Nil, Value::Boolean(true))]), val.as_map());

assert_eq!(None, Value::Nil.as_map());

fn as_ext(&self) -> Option<(i8, &[u8])>

If the Value is an Ext, returns the associated tuple with a ty and slice. Returns None otherwise.

Examples

use rmp::Value;

assert_eq!(Some((42, &[1, 2, 3, 4, 5][..])), Value::Ext(42, vec![1, 2, 3, 4, 5]).as_ext());

assert_eq!(None, Value::Boolean(true).as_ext());

Trait Implementations

impl PartialEq for Value
[src]

fn eq(&self, __arg_0: &Value) -> bool

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

fn ne(&self, __arg_0: &Value) -> bool

This method tests for !=.

impl Debug for Value
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Clone for Value
[src]

fn clone(&self) -> Value

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Index<usize> for Value
[src]

type Output = Value

The returned type after indexing

fn index(&self, index: usize) -> &Value

The method for the indexing (Foo[Bar]) operation

impl From<bool> for Value
[src]

fn from(v: bool) -> Value

Performs the conversion.

impl From<u8> for Value
[src]

fn from(v: u8) -> Value

Performs the conversion.

impl From<u16> for Value
[src]

fn from(v: u16) -> Value

Performs the conversion.

impl From<u32> for Value
[src]

fn from(v: u32) -> Value

Performs the conversion.

impl From<u64> for Value
[src]

fn from(v: u64) -> Value

Performs the conversion.

impl From<usize> for Value
[src]

fn from(v: usize) -> Value

Performs the conversion.

impl From<i8> for Value
[src]

fn from(v: i8) -> Value

Performs the conversion.

impl From<i16> for Value
[src]

fn from(v: i16) -> Value

Performs the conversion.

impl From<i32> for Value
[src]

fn from(v: i32) -> Value

Performs the conversion.

impl From<i64> for Value
[src]

fn from(v: i64) -> Value

Performs the conversion.

impl From<isize> for Value
[src]

fn from(v: isize) -> Value

Performs the conversion.

impl From<f32> for Value
[src]

fn from(v: f32) -> Value

Performs the conversion.

impl From<f64> for Value
[src]

fn from(v: f64) -> Value

Performs the conversion.

impl Display for Value
[src]

Implements human-readable value formatting.

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.