pub enum Value {
}
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
impl Value
sourcepub fn is_null(&self) -> bool
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());
sourcepub fn is_bool(&self) -> bool
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());
sourcepub fn is_i64(&self) -> bool
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());
sourcepub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the Value
is convertible to an u64. Returns false otherwise.
sourcepub fn is_f32(&self) -> bool
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());
sourcepub fn is_f64(&self) -> bool
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());
sourcepub fn is_number(&self) -> bool
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());
sourcepub fn is_str(&self) -> bool
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());
sourcepub fn as_bool(&self) -> Option<bool>
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());
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If the Value
is an integer, return or cast it to a i64.
Returns None otherwise.
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
If the Value
is an integer, return or cast it to a u64.
Returns None otherwise.
sourcepub fn as_f64(&self) -> Option<f64>
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());
sourcepub fn as_str(&self) -> Option<&str>
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());
pub fn as_string(&self) -> Option<String>
pub fn into_string(self) -> Option<String>
sourcepub fn into_bytes(self) -> Option<Vec<u8>>
pub fn into_bytes(self) -> Option<Vec<u8>>
self to Binary
sourcepub fn as_slice(&self) -> Option<&[u8]>
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());
sourcepub fn as_array(&self) -> Option<&Vec<Value>>
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());
sourcepub fn as_map(&self) -> Option<&ValueMap>
pub fn as_map(&self) -> Option<&ValueMap>
If the Value
is a Map, returns the associated vector of key-value tuples.
Returns None otherwise.
sourcepub fn as_ext(&self) -> Option<(&str, &Box<Value>)>
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.
pub fn into_map(self) -> Option<ValueMap>
pub fn into_array(self) -> Option<Vec<Value>>
Trait Implementations§
source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
source§fn deserialize<D>(de: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(de: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'de> Deserializer<'de> for &Value
impl<'de> Deserializer<'de> for &Value
source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read moresource§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moresource§fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u8
value.source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u16
value.source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u32
value.source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a u64
value.source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i8
value.source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i16
value.source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i32
value.source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting an i64
value.source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f32
value.source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a f64
value.source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit value.source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read moresource§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moresource§fn deserialize_i128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_i128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
source§fn deserialize_u128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_u128<V>(
self,
visitor: V
) -> Result<<V as Visitor<'de>>::Value, Self::Error>where
V: Visitor<'de>,
source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize
implementations should expect to
deserialize their human-readable form. Read moresource§impl<V> FromIterator<V> for Value
impl<V> FromIterator<V> for Value
source§fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self
source§impl<'a> IntoIterator for &'a Value
impl<'a> IntoIterator for &'a Value
source§impl IntoIterator for Value
impl IntoIterator for Value
source§impl PartialEq for Value
impl PartialEq for Value
impl Eq for Value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.