#[non_exhaustive]pub enum Value {
Unsigned(u64),
Negative(i128),
Bytes(Vec<u8>),
Text(String),
Array(Vec<Self>),
Map(Vec<(Self, Self)>),
Tag(u64, Box<Self>),
Simple(u8),
Bool(bool),
Null,
Undefined,
Float(f64),
}Expand description
An owned, dynamically typed CBOR value.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Unsigned(u64)
An unsigned integer.
Negative(i128)
A negative integer.
Bytes(Vec<u8>)
A byte string.
Text(String)
A UTF-8 text string.
Array(Vec<Self>)
An array of values.
Map(Vec<(Self, Self)>)
An ordered collection of key-value pairs.
Tag(u64, Box<Self>)
A semantic tag and its tagged value.
Simple(u8)
An unassigned simple value.
Bool(bool)
A Boolean value.
Null
The null value.
Undefined
The undefined value.
Float(f64)
A floating-point value represented as binary64.
Implementations§
Source§impl Value
impl Value
Sourcepub const fn is_unsigned(&self) -> bool
pub const fn is_unsigned(&self) -> bool
Returns true if this is an Unsigned value.
Sourcepub const fn is_integer(&self) -> bool
pub const fn is_integer(&self) -> bool
Returns true if this is an unsigned or negative integer.
Tags 2 and 3 (bignums) are deliberately not treated as integers. Their interpretation depends on the tagged byte string and must be explicit.
Sourcepub const fn is_undefined(&self) -> bool
pub const fn is_undefined(&self) -> bool
Returns true if this is undefined.
Sourcepub const fn as_unsigned(&self) -> Option<u64>
pub const fn as_unsigned(&self) -> Option<u64>
Returns the unsigned integer, if present.
Sourcepub fn as_integer(&self) -> Option<i128>
pub fn as_integer(&self) -> Option<i128>
Returns the integer as an i128, if present and representable.
This accepts both native integer variants but not bignum tags.
Sourcepub fn as_bytes_mut(&mut self) -> Option<&mut Vec<u8>>
pub fn as_bytes_mut(&mut self) -> Option<&mut Vec<u8>>
Mutably borrows the byte string, if present.
Sourcepub fn as_text_mut(&mut self) -> Option<&mut String>
pub fn as_text_mut(&mut self) -> Option<&mut String>
Mutably borrows the text string, if present.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
Mutably borrows the array, if present.
Sourcepub fn as_map(&self) -> Option<&[(Self, Self)]>
pub fn as_map(&self) -> Option<&[(Self, Self)]>
Borrows the ordered map entries, if present.
The slice retains insertion/wire order and may contain duplicate keys.
Sourcepub fn as_map_mut(&mut self) -> Option<&mut Vec<(Self, Self)>>
pub fn as_map_mut(&mut self) -> Option<&mut Vec<(Self, Self)>>
Mutably borrows the ordered map entries, if present.
Sourcepub fn as_tag(&self) -> Option<(u64, &Self)>
pub fn as_tag(&self) -> Option<(u64, &Self)>
Returns the tag number and tagged value, if present.
Sourcepub fn into_bytes(self) -> Result<Vec<u8>, Self>
pub fn into_bytes(self) -> Result<Vec<u8>, Self>
Extracts the byte string without cloning, or returns the original value.
Sourcepub fn into_text(self) -> Result<String, Self>
pub fn into_text(self) -> Result<String, Self>
Extracts the text string without cloning, or returns the original value.
Sourcepub fn into_array(self) -> Result<Vec<Self>, Self>
pub fn into_array(self) -> Result<Vec<Self>, Self>
Extracts the array without cloning, or returns the original value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Value
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl From<BorrowedValue<'_>> for Value
impl From<BorrowedValue<'_>> for Value
Source§fn from(v: BorrowedValue<'_>) -> Self
fn from(v: BorrowedValue<'_>) -> Self
Source§impl From<Value> for BorrowedValue<'static>
impl From<Value> for BorrowedValue<'static>
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 UnsafeUnpin 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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