Skip to main content

Value

Enum Value 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const fn is_unsigned(&self) -> bool

Returns true if this is an Unsigned value.

Source

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.

Source

pub const fn is_bytes(&self) -> bool

Returns true if this is a byte string.

Source

pub const fn is_text(&self) -> bool

Returns true if this is a text string.

Source

pub const fn is_array(&self) -> bool

Returns true if this is an array.

Source

pub const fn is_map(&self) -> bool

Returns true if this is a map.

Source

pub const fn is_tag(&self) -> bool

Returns true if this is a tagged value.

Source

pub const fn is_simple(&self) -> bool

Returns true if this is an unassigned simple value.

Source

pub const fn is_bool(&self) -> bool

Returns true if this is a Boolean.

Source

pub const fn is_null(&self) -> bool

Returns true if this is null.

Source

pub const fn is_undefined(&self) -> bool

Returns true if this is undefined.

Source

pub const fn is_float(&self) -> bool

Returns true if this is a floating-point value.

Source

pub const fn as_unsigned(&self) -> Option<u64>

Returns the unsigned integer, if present.

Source

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.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Borrows the byte string, if present.

Source

pub fn as_bytes_mut(&mut self) -> Option<&mut Vec<u8>>

Mutably borrows the byte string, if present.

Source

pub fn as_text(&self) -> Option<&str>

Borrows the text string, if present.

Source

pub fn as_text_mut(&mut self) -> Option<&mut String>

Mutably borrows the text string, if present.

Source

pub fn as_array(&self) -> Option<&[Self]>

Borrows the array, if present.

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>

Mutably borrows the array, if present.

Source

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.

Source

pub fn as_map_mut(&mut self) -> Option<&mut Vec<(Self, Self)>>

Mutably borrows the ordered map entries, if present.

Source

pub fn as_tag(&self) -> Option<(u64, &Self)>

Returns the tag number and tagged value, if present.

Source

pub const fn as_simple(&self) -> Option<u8>

Returns the simple value, if present.

Source

pub const fn as_bool(&self) -> Option<bool>

Returns the Boolean, if present.

Source

pub const fn as_float(&self) -> Option<f64>

Returns the floating-point value, if present.

Source

pub fn into_bytes(self) -> Result<Vec<u8>, Self>

Extracts the byte string without cloning, or returns the original value.

Source

pub fn into_text(self) -> Result<String, Self>

Extracts the text string without cloning, or returns the original value.

Source

pub fn into_array(self) -> Result<Vec<Self>, Self>

Extracts the array without cloning, or returns the original value.

Source

pub fn into_map(self) -> Result<Vec<(Self, Self)>, Self>

Extracts the ordered map entries without cloning, or returns the original value.

Source

pub fn encode<W: Output>(&self, e: &mut Encoder<W>) -> Result<()>

Encodes this value through a low-level Encoder.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Value

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&[u8]> for Value

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from((): ()) -> Self

Converts to this type from the input type.
Source§

impl From<BorrowedValue<'_>> for Value

Source§

fn from(v: BorrowedValue<'_>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for BorrowedValue<'static>

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(Value, Value)>> for Value

Source§

fn from(value: Vec<(Value, Value)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(value: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Value

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Value

Source§

impl TryFrom<Value> for bool

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for f64

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for String

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<u8>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<Value>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for Vec<(Value, Value)>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for u8

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for u16

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for u32

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for u64

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for u128

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for i8

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for i16

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for i32

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for i64

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Value> for i128

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.