Enum Value

Source
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

Source

pub fn is_object(&self) -> bool

Returns true if the value is an object.

Source

pub fn as_object(&self) -> Option<&BTreeMap<ObjectKey, Value>>

If the value is an object, returns the associated BTreeMap. Returns None otherwise.

Source

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.

Source

pub fn is_array(&self) -> bool

Returns true if the value is an array.

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

If the value is an array, returns the associated Vec. Returns None otherwise.

Source

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.

Source

pub fn is_bytes(&self) -> bool

Returns true if the value is a byte string.

Source

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

Returns the associated byte string or None if the value has a different type.

Source

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.

Source

pub fn is_string(&self) -> bool

Returns true if the value is a string.

Source

pub fn as_string(&self) -> Option<&String>

Returns the associated string or None if the value has a different type.

Source

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

Returns the associated mutable string or None if the value has a different type.

Source

pub fn is_number(&self) -> bool

Retrns true if the value is a number.

Source

pub fn is_i64(&self) -> bool

Returns true if the Value is a i64. Returns false otherwise.

Source

pub fn is_u64(&self) -> bool

Returns true if the Value is a u64. Returns false otherwise.

Source

pub fn is_f64(&self) -> bool

Returns true if the Value is a f64. Returns false otherwise.

Source

pub fn as_i64(&self) -> Option<i64>

If the Value is a number, return or cast it to a i64. Returns None otherwise.

Source

pub fn as_u64(&self) -> Option<u64>

If the Value is a number, return or cast it to a u64. Returns None otherwise.

Source

pub fn as_f64(&self) -> Option<f64>

If the Value is a number, return or cast it to a f64. Returns None otherwise.

Source

pub fn is_boolean(&self) -> bool

Returns true if the value is a boolean.

Source

pub fn as_boolean(&self) -> Option<bool>

If the value is a Boolean, returns the associated bool. Returns None otherwise.

Source

pub fn is_null(&self) -> bool

Returns true if the value is a Null. Returns false otherwise.

Source

pub fn as_null(&self) -> Option<()>

If the value is a Null, returns (). Returns None otherwise.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · 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<(), Error>

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

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

Source§

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

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

impl From<BTreeMap<ObjectKey, Value>> for Value

Source§

fn from(v: BTreeMap<ObjectKey, Value>) -> Value

Converts to this type from the input type.
Source§

impl From<ObjectKey> for Value

Source§

fn from(key: ObjectKey) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(v: Vec<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Value

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Value

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

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

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

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

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,