Struct rmp_serde::Value [] [src]

pub struct Value(pub Value);

Owning wrapper over rmp Value to allow serialization and deserialization.

Methods from Deref<Target=Value>

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

Examples

use rmp::Value;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Trait Implementations

impl Debug for Value
[src]

Formats the value using the given formatter.

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 Clone for Value
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Deref for Value
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<T: Into<Value>> From<T> for Value
[src]

Performs the conversion.

impl Serialize for Value
[src]

Serializes this value into this serializer.

impl Deserialize for Value
[src]

Deserialize this value given this Deserializer.