pub enum Value {
    Nil,
    Boolean(bool),
    Integer(Integer),
    F32(f32),
    F64(f64),
    String(Utf8String),
    Binary(Vec<u8, Global>),
    Array(Vec<Value, Global>),
    Map(Vec<(Value, Value), Global>),
    Ext(i8Vec<u8, Global>),
}
Expand description

Represents any valid MessagePack value.

Variants§

§

Nil

Nil represents nil.

§

Boolean(bool)

Boolean represents true or false.

§

Integer(Integer)

Integer represents an integer.

A value of an Integer object is limited from -(2^63) upto (2^64)-1.

Examples

use rmpv::Value;

assert_eq!(42, Value::from(42).as_i64().unwrap());
§

F32(f32)

A 32-bit floating point number.

§

F64(f64)

A 64-bit floating point number.

§

String(Utf8String)

String extending Raw type represents a UTF-8 string.

Note

String objects may contain invalid byte sequence and the behavior of a deserializer depends on the actual implementation when it received invalid byte sequence. Deserializers should provide functionality to get the original byte array so that applications can decide how to handle the object

§

Binary(Vec<u8, Global>)

Binary extending Raw type represents a byte array.

§

Array(Vec<Value, Global>)

Array represents a sequence of objects.

§

Map(Vec<(Value, Value), Global>)

Map represents key-value pairs of objects.

§

Ext(i8Vec<u8, Global>)

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.

Implementations§

Converts the current owned Value to a ValueRef.

Panics

Panics in unable to allocate memory to keep all internal structures and buffers.

Examples
use rmpv::{Value, ValueRef};

let val = Value::Array(vec![
    Value::Nil,
    Value::from(42),
    Value::Array(vec![
        Value::String("le message".into())
    ])
]);

let expected = ValueRef::Array(vec![
   ValueRef::Nil,
   ValueRef::from(42),
   ValueRef::Array(vec![
       ValueRef::from("le message"),
   ])
]);

assert_eq!(expected, val.as_ref());

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

Examples
use rmpv::Value;

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

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

Examples
use rmpv::Value;

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

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

Returns true if the Value is convertible to an i64. Returns false otherwise.

Examples
use rmpv::Value;

assert!(Value::from(42).is_i64());

assert!(!Value::from(42.0).is_i64());

Returns true if the Value is convertible to an u64. Returns false otherwise.

Examples
use rmpv::Value;

assert!(Value::from(42).is_u64());

assert!(!Value::F32(42.0).is_u64());
assert!(!Value::F64(42.0).is_u64());

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

Examples
use rmpv::Value;

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

assert!(!Value::from(42).is_f32());
assert!(!Value::F64(42.0).is_f32());

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

Examples
use rmpv::Value;

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

assert!(!Value::from(42).is_f64());
assert!(!Value::F32(42.0).is_f64());

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

Examples
use rmpv::Value;

assert!(Value::from(42).is_number());
assert!(Value::F32(42.0).is_number());
assert!(Value::F64(42.0).is_number());

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

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

Examples
use rmpv::Value;

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

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

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 rmpv::Value;

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

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

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

Examples
use rmpv::Value;

assert_eq!(Some(42i64), Value::from(42).as_i64());

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

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

Examples
use rmpv::Value;

assert_eq!(Some(42u64), Value::from(42).as_u64());

assert_eq!(None, Value::from(-42).as_u64());
assert_eq!(None, Value::F64(42.0).as_u64());

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

Examples
use rmpv::Value;

assert_eq!(Some(42.0), Value::from(42).as_f64());
assert_eq!(Some(42.0), Value::F32(42.0f32).as_f64());
assert_eq!(Some(42.0), Value::F64(42.0f64).as_f64());

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

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

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

Examples
use rmpv::Value;

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

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

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

Examples
use rmpv::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());

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

Examples
use rmpv::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());

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 rmpv::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());

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

Examples
use rmpv::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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
The error type that can be returned if some error occurs during deserialization.
Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Hint that the Deserialize type is expecting an optional value. Read more
Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
Hint that the Deserialize type is expecting a newtype struct with a particular name.
Hint that the Deserialize type is expecting a unit struct with a particular name.
Hint that the Deserialize type is expecting a bool value.
Hint that the Deserialize type is expecting a u8 value.
Hint that the Deserialize type is expecting a u16 value.
Hint that the Deserialize type is expecting a u32 value.
Hint that the Deserialize type is expecting a u64 value.
Hint that the Deserialize type is expecting an i8 value.
Hint that the Deserialize type is expecting an i16 value.
Hint that the Deserialize type is expecting an i32 value.
Hint that the Deserialize type is expecting an i64 value.
Hint that the Deserialize type is expecting a f32 value.
Hint that the Deserialize type is expecting a f64 value.
Hint that the Deserialize type is expecting a char value.
Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Hint that the Deserialize type is expecting a unit value.
Hint that the Deserialize type is expecting a sequence of values.
Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Hint that the Deserialize type is expecting a map of key-value pairs.
Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
Hint that the Deserialize type is expecting a struct with a particular name and fields.
Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Hint that the Deserialize type is expecting an i128 value. Read more
Hint that the Deserialize type is expecting an u128 value. Read more
Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Note that an Iterator<Item = u8> will be collected into an Array, rather than a Binary

Creates a value from an iterator. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
TODO: once 1.33.0 is the minimum supported compiler version, remove Any::type_id_compat and use StdAny::type_id instead. https://github.com/rust-lang/rust/issues/27745
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more