#[non_exhaustive]pub enum Value<'a> {
Null,
Bool(bool),
Undefined,
Simple(u8),
Integer(i128),
Float(f64),
Bytes(Cow<'a, [u8]>),
Text(Cow<'a, str>),
Array(Vec<Value<'a>>),
Map(BTreeMap<Value<'a>, Value<'a>>),
Tag(u64, Box<Value<'a>>),
}Expand description
A dynamically-typed CBOR value.
#[non_exhaustive]: CBOR’s shapes are open, so a downstream match over
every variant would need editing for each addition here.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
Major type 7, the null simple value.
Bool(bool)
Major type 7, true or false.
Undefined
Major type 7, simple value 23: undefined. Distinct from
Value::Null, which says a value is absent.
Simple(u8)
Major type 7, a simple value with no meaning of its own. RFC 8949 Section 3.3 reserves these, so they are carried rather than rejected.
Integer(i128)
Major type 0 or 1: a non-negative or negative integer.
Float(f64)
Major type 7, a half-, single-, or double-precision float.
Bytes(Cow<'a, [u8]>)
Major type 2, a byte string.
Text(Cow<'a, str>)
Major type 3, a UTF-8 text string.
Array(Vec<Value<'a>>)
Major type 4, an array of values.
Map(BTreeMap<Value<'a>, Value<'a>>)
Major type 5, a map from values to values.
Tag(u64, Box<Value<'a>>)
Major type 6, a tagged value: the tag number and the value it applies to.
Implementations§
Source§impl<'a> Value<'a>
impl<'a> Value<'a>
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the value is an integer.
Sourcepub fn as_integer(&self) -> Option<i128>
pub fn as_integer(&self) -> Option<i128>
Returns the value as an integer if it is one.
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns the value as a byte slice if it is a byte string.
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Returns the value as a string slice if it is a text string.
Trait Implementations§
impl<'a> Eq for Value<'a>
Source§impl<'a> Ord for Value<'a>
impl<'a> Ord for Value<'a>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
The order RFC 8949 Section 4.2.1 defines for map keys: bytewise over their deterministic encodings.
A BTreeMap iterates in this order, so a map of values comes out
deterministic with no sorting at write time. Heads go first, which
settles major type and float width without walking contents; equal heads
mean the same shape, since CBOR is self-delimiting, so the rest is
content.
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a> PartialEq for Value<'a>
impl<'a> PartialEq for Value<'a>
Source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
A NaN equals itself here, unlike the f64 it rides in.
A CBOR NaN has no payload a decoder must keep: RFC 8949 Section 4.1
names one encoding and Section 4.2.1 requires it. Leaving the derived
comparison would make Eq unsound and a BTreeMap<Value, _> would
treat each NaN as a fresh key.
Source§impl<'a> PartialOrd for Value<'a>
impl<'a> PartialOrd for Value<'a>
Source§impl<'a> ToCbor for Value<'a>
impl<'a> ToCbor for Value<'a>
Source§fn write<W: Write>(&self, writer: &mut W) -> Result<()>
fn write<W: Write>(&self, writer: &mut W) -> Result<()>
Source§fn size_hint(&self) -> Option<TrustedSizeHint>
fn size_hint(&self) -> Option<TrustedSizeHint>
Self::write will
write, or None if it cannot be had cheaply. Read more