pub enum ValueRef<'a> {
Nil,
Boolean(bool),
Integer(Integer),
F32(f32),
F64(f64),
String(Utf8StringRef<'a>),
Binary(&'a [u8]),
Array(Vec<ValueRef<'a>>),
Map(Vec<(ValueRef<'a>, ValueRef<'a>)>),
Ext(i8, &'a [u8]),
}
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
.
F32(f32)
A 32-bit floating point number.
F64(f64)
A 64-bit floating point number.
String(Utf8StringRef<'a>)
String extending Raw type represents a UTF-8 string.
Binary(&'a [u8])
Binary extending Raw type represents a byte array.
Array(Vec<ValueRef<'a>>)
Array represents a sequence of objects.
Map(Vec<(ValueRef<'a>, ValueRef<'a>)>)
Map represents key-value pairs of objects.
Ext(i8, &'a [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.
Implementations§
source§impl<'a> ValueRef<'a>
impl<'a> ValueRef<'a>
sourcepub fn to_owned(&self) -> Value
pub fn to_owned(&self) -> Value
Converts the current non-owning value to an owned Value.
This is achieved by deep copying all underlying structures and borrowed buffers.
§Panics
Panics in unable to allocate memory to keep all internal structures and buffers.
§Examples
use rmpv::{Value, ValueRef};
let val = ValueRef::Array(vec![
ValueRef::Nil,
ValueRef::from(42),
ValueRef::Array(vec![
ValueRef::from("le message"),
])
]);
let expected = Value::Array(vec![
Value::Nil,
Value::from(42),
Value::Array(vec![
Value::String("le message".into())
])
]);
assert_eq!(expected, val.to_owned());
pub fn index(&self, index: usize) -> &ValueRef<'_>
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
If the ValueRef
is an integer, return or cast it to a u64.
Returns None otherwise.
§Examples
use rmpv::ValueRef;
assert_eq!(Some(42), ValueRef::from(42).as_u64());
sourcepub fn as_array(&self) -> Option<&Vec<ValueRef<'_>>>
pub fn as_array(&self) -> Option<&Vec<ValueRef<'_>>>
If the ValueRef
is an Array, returns the associated vector.
Returns None otherwise.
§Examples
use rmpv::ValueRef;
let val = ValueRef::Array(vec![ValueRef::Nil, ValueRef::Boolean(true)]);
assert_eq!(Some(&vec![ValueRef::Nil, ValueRef::Boolean(true)]), val.as_array());
assert_eq!(None, ValueRef::Nil.as_array());