pub enum Value {
U64(u64),
I64(i64),
Bytes(Vec<u8>),
String(String),
Array(Vec<Value>),
Object(BTreeMap<ObjectKey, Value>),
F64(f64),
Bool(bool),
Null,
}
Expand description
An enum over all possible CBOR types.
Variants§
U64(u64)
Represents an unsigned integer.
I64(i64)
Represents a signed integer.
Bytes(Vec<u8>)
Represents a byte string.
String(String)
Represents an UTF-8 string.
Array(Vec<Value>)
Represents a list.
Object(BTreeMap<ObjectKey, Value>)
Represents a map.
F64(f64)
Represents a floating point value.
Bool(bool)
Represents a boolean value.
Null
Represents the absence of a value or the value undefined.
Implementations§
Source§impl Value
impl Value
Sourcepub fn as_object(&self) -> Option<&BTreeMap<ObjectKey, Value>>
pub fn as_object(&self) -> Option<&BTreeMap<ObjectKey, Value>>
If the value is an object, returns the associated BTreeMap. Returns None otherwise.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<ObjectKey, Value>>
pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<ObjectKey, Value>>
If the value is an object, returns the associated mutable BTreeMap. Returns None otherwise.
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 Vec. Returns None otherwise.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
If the value is an array, returns the associated mutable Vec. Returns None otherwise.
Sourcepub fn as_bytes(&self) -> Option<&Vec<u8>>
pub fn as_bytes(&self) -> Option<&Vec<u8>>
Returns the associated byte string or None
if the value has a different type.
Sourcepub fn as_bytes_mut(&mut self) -> Option<&mut Vec<u8>>
pub fn as_bytes_mut(&mut self) -> Option<&mut Vec<u8>>
Returns the associated mutable byte string or None
if the value has a different type.
Sourcepub fn as_string(&self) -> Option<&String>
pub fn as_string(&self) -> Option<&String>
Returns the associated string or None
if the value has a different type.
Sourcepub fn as_string_mut(&mut self) -> Option<&mut String>
pub fn as_string_mut(&mut self) -> Option<&mut String>
Returns the associated mutable string or None
if the value has a different type.
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If the Value
is a number, 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 a number, 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.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if the value is a boolean.
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
If the value is a Boolean, returns the associated bool. Returns None otherwise.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Value, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Serialize for Value
impl Serialize for Value
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more