serde_brief::value

Enum Value

source
pub enum Value<'a> {
    Null,
    Bool(bool),
    Integer(Integer),
    Float(Float),
    Bytes(Cow<'a, [u8]>),
    String(Cow<'a, str>),
    Array(VecDeque<Self>),
    Map(VecDeque<(Self, Self)>),
}
Expand description

Generic value that can contain any value in our data format. It can be deserialized and serialized to be exactly as when serializing or deserializing with the given type.

Note: Cloneing this value will not borrow from owned values. For that, you need to call Value::borrow_clone.

Variants§

§

Null

Null / None / Unit type.

§

Bool(bool)

Bool value.

§

Integer(Integer)

Integer value.

§

Float(Float)

Float value.

§

Bytes(Cow<'a, [u8]>)

Bytes value.

§

String(Cow<'a, str>)

String value.

§

Array(VecDeque<Self>)

Sequence value.

§

Map(VecDeque<(Self, Self)>)

Map value (ordered).

Implementations§

source§

impl<'a> Value<'a>

source

pub fn borrow_clone(&self) -> Value<'_>

Clone this value, borrowing the owned data where possible.

source

pub fn into_owned(self) -> OwnedValue

Make value 'static by cloning all borrowed data.

source

pub fn deserialize_as<'de, T>(self) -> Result<T>
where T: Deserialize<'de>, 'a: 'de,

Use this generic Value to deserialize into the given concrete type.

source

pub fn is_empty(&self) -> bool

Return whether the value is empty. This is the case if:

source

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

Return the inner bool if this is a Value::Bool.

source

pub const fn as_int(&self) -> Option<Integer>

Return the inner int if this is a Value::Integer.

source

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

Return the inner float if this is a Value::Float.

source

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

Return the inner bytes if this is a Value::Bytes.

source

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

Return the inner string if this is a Value::String.

source

pub const fn as_array(&self) -> Option<&VecDeque<Value<'a>>>

Return the inner array if this is a Value::Array.

source

pub const fn as_map(&self) -> Option<&VecDeque<(Value<'a>, Value<'a>)>>

Return the inner map if this is a Value::Map.

source

pub fn into_values(self) -> Iter<Value<'static>>

Iterate over the inner values if this is a Value::Array or Value::Map.

Trait Implementations§

source§

impl<'a> Clone for Value<'a>

source§

fn clone(&self) -> Value<'a>

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<'a> Debug for Value<'a>

source§

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

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

impl<'a> Default for Value<'a>

source§

fn default() -> Value<'a>

Returns the “default value” for a type. Read more
source§

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

source§

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

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

impl<'a> Display for Value<'a>

source§

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

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

impl<'a> From<&'a [u8]> for Value<'a>

source§

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

Converts to this type from the input type.
source§

impl<'a, 'de> From<&'a Value<'de>> for Unexpected<'a>

source§

fn from(value: &'a Value<'de>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for Value<'a>

source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<()> for Value<'a>

source§

fn from(_: ()) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, [u8]>> for Value<'a>

source§

fn from(value: Cow<'a, [u8]>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for Value<'a>

source§

fn from(value: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Option<Value<'a>>> for Value<'a>

source§

fn from(value: Option<Value<'a>>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<String> for Value<'a>

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Vec<u8>> for Value<'a>

source§

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

Converts to this type from the input type.
source§

impl<'a> From<VecDeque<(Value<'a>, Value<'a>)>> for Value<'a>

source§

fn from(value: VecDeque<(Value<'a>, Value<'a>)>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<VecDeque<Value<'a>>> for Value<'a>

source§

fn from(value: VecDeque<Value<'a>>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<bool> for Value<'a>

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl<'a> From<f32> for Value<'a>

source§

fn from(value: f32) -> Self

Converts to this type from the input type.
source§

impl<'a> From<f64> for Value<'a>

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<i128> for Value<'a>

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl<'a> From<i16> for Value<'a>

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl<'a> From<i32> for Value<'a>

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl<'a> From<i64> for Value<'a>

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<i8> for Value<'a>

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl<'a> From<isize> for Value<'a>

source§

fn from(value: isize) -> Self

Converts to this type from the input type.
source§

impl<'a> From<u128> for Value<'a>

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl<'a> From<u16> for Value<'a>

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl<'a> From<u32> for Value<'a>

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl<'a> From<u64> for Value<'a>

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<u8> for Value<'a>

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl<'a> From<usize> for Value<'a>

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl<'a, K, V> FromIterator<(K, V)> for Value<'a>
where K: Into<Value<'a>>, V: Into<Value<'a>>,

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a, T> FromIterator<T> for Value<'a>
where T: Into<Value<'a>>,

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> PartialEq<[u8]> for Value<'a>

source§

fn eq(&self, other: &[u8]) -> 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<'a> PartialEq<bool> for Value<'a>

source§

fn eq(&self, other: &bool) -> 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<'a> PartialEq<f32> for Value<'a>

source§

fn eq(&self, other: &f32) -> 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<'a> PartialEq<f64> for Value<'a>

source§

fn eq(&self, other: &f64) -> 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<'a> PartialEq<i128> for Value<'a>

source§

fn eq(&self, other: &i128) -> 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<'a> PartialEq<str> for Value<'a>

source§

fn eq(&self, other: &str) -> 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<'a> PartialEq<u128> for Value<'a>

source§

fn eq(&self, other: &u128) -> 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<'a> PartialEq for Value<'a>

source§

fn eq(&self, other: &Self) -> 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<'a> Serialize for Value<'a>

source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Value<'a>

§

impl<'a> RefUnwindSafe for Value<'a>

§

impl<'a> Send for Value<'a>

§

impl<'a> Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> UnwindSafe for Value<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.