Enum rbs::value::Value

source ·
pub enum Value {
Show 13 variants Null, Bool(bool), I32(i32), I64(i64), U32(u32), U64(u64), F32(f32), F64(f64), String(String), Binary(Vec<u8>), Array(Vec<Self>), Map(ValueMap), Ext(&'static str, Box<Self>),
}
Expand description

Represents any valid MessagePack value.

Variants§

§

Null

null

§

Bool(bool)

true or false

§

I32(i32)

Int32

§

I64(i64)

Int64

§

U32(u32)

Uint32

§

U64(u64)

Uint64

§

F32(f32)

A 32-bit float number.

§

F64(f64)

A 64-bit float number.

§

String(String)

String

§

Binary(Vec<u8>)

Binary/Bytes.

§

Array(Vec<Self>)

Array/Vec.

§

Map(ValueMap)

Map<Key,Value>.

§

Ext(&'static str, Box<Self>)

Extended implements Extension interface

Implementations§

source§

impl Value

source

pub fn insert(&mut self, key: Value, value: Value) -> Option<Value>

source

pub fn remove(&mut self, key: &Value) -> Value

source§

impl Value

source

pub fn is_null(&self) -> bool

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

§Examples
use rbs::Value;

assert!(Value::Null.is_null());
source

pub fn is_bool(&self) -> bool

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

§Examples
use rbs::Value;

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

assert!(!Value::Null.is_bool());
source

pub fn is_i64(&self) -> bool

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

§Examples
use rbs::Value;

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

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

pub fn is_u64(&self) -> bool

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

source

pub fn is_f32(&self) -> bool

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

§Examples
use rbs::Value;

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

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

pub fn is_f64(&self) -> bool

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

§Examples
use rbs::Value;

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

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

pub fn is_number(&self) -> bool

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

§Examples
use rbs::Value;

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

assert!(!Value::Null.is_number());
source

pub fn is_str(&self) -> bool

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

§Examples
use rbs::Value;

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

assert!(!Value::Null.is_str());
source

pub fn is_bin(&self) -> bool

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

source

pub fn is_array(&self) -> bool

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

source

pub fn is_map(&self) -> bool

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

source

pub fn is_ext(&self) -> bool

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

source

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

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

§Examples
use rbs::Value;

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

assert_eq!(None, Value::Null.as_bool());
source

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

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

source

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

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

source

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

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

§Examples
use rbs::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::Null.as_f64());
source

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

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

§Examples
use rbs::Value;

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

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

pub fn as_string(&self) -> Option<String>

source

pub fn into_string(self) -> Option<String>

source

pub fn into_bytes(self) -> Option<Vec<u8>>

self to Binary

source

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

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

§Examples
use rbs::Value;

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

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

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

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

§Examples
use rbs::Value;

let val = Value::Array(vec![Value::Null, Value::Bool(true)]);

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

assert_eq!(None, Value::Null.as_array());
source

pub fn as_map(&self) -> Option<&ValueMap>

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

source

pub fn as_ext(&self) -> Option<(&str, &Box<Value>)>

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

source

pub fn into_map(self) -> Option<ValueMap>

source

pub fn into_array(self) -> Option<Vec<Value>>

source§

impl Value

source

pub fn into_ext(self, name: &'static str) -> Self

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

return array/map/string’s length

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Value

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Value

source§

fn deserialize<D>(de: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'de> Deserializer<'de> for &Value

§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
source§

fn deserialize_enum<V>( self, _name: &str, _variants: &'static [&'static str], visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
source§

fn deserialize_newtype_struct<V>( self, _name: &'static str, visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
source§

fn deserialize_unit_struct<V>( self, _name: &'static str, visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
source§

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
source§

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
source§

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
source§

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
source§

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
source§

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
source§

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
source§

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
source§

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
source§

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
source§

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
source§

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
source§

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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
source§

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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
source§

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
source§

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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
source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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
source§

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
source§

fn deserialize_tuple_struct<V>( self, name: &'static str, len: usize, visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
source§

fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
source§

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
source§

fn deserialize_tuple<V>( self, len: usize, visitor: V ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
source§

fn deserialize_i128<V>( self, visitor: V ) -> Result<<V as Visitor<'de>>::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
source§

fn deserialize_u128<V>( self, visitor: V ) -> Result<<V as Visitor<'de>>::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
source§

impl Display for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a [u8]> for Value

source§

fn from(v: &[u8]) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for String

source§

fn from(arg: &Value) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for bool

source§

fn from(arg: &Value) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for f64

source§

fn from(arg: &Value) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for i64

source§

fn from(arg: &Value) -> Self

Converts to this type from the input type.
source§

impl From<&Value> for u64

source§

fn from(arg: &Value) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for Value

source§

fn from(v: &str) -> Self

Converts to this type from the input type.
source§

impl From<(&'static str, Value)> for Value

from tuple for ext

source§

fn from(arg: (&'static str, Value)) -> Self

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(v: String) -> Self

Converts to this type from the input type.
source§

impl From<Value> for String

source§

fn from(arg: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for bool

source§

fn from(arg: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for f64

source§

fn from(arg: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for i64

source§

fn from(arg: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for u64

source§

fn from(arg: Value) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Value>> for Value

source§

fn from(v: Vec<Value>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for Value

source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Value

source§

fn from(v: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(v: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Value

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(v: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Value

source§

fn from(v: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Value

source§

fn from(v: isize) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Value

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Value

source§

fn from(v: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Value

source§

fn from(v: usize) -> Self

Converts to this type from the input type.
source§

impl<V> FromIterator<V> for Value
where V: Into<Value>,

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

source§

fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Value

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<&str> for Value

§

type Output = Value

The returned type after indexing.
source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<usize> for Value

§

type Output = Value

The returned type after indexing.
source§

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

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<&str> for Value

source§

fn index_mut(&mut self, index: &str) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Value

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl Into<ValueMap> for Value

source§

fn into(self) -> ValueMap

Converts this type into the (usually inferred) input type.
source§

impl Into<Vec<Value>> for Value

into vec value

source§

fn into(self) -> Vec<Value>

Converts this type into the (usually inferred) input type.
source§

impl<'a> IntoIterator for &'a Value

§

type Item = (Value, &'a Value)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<(Value, &'a Value)>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Value

§

type Item = (Value, Value)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Value, Value>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Value

source§

fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Value

source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,