Value

Enum Value 

Source
pub enum Value<'v> {
Show 30 variants Bool(bool), I8(i8), I16(i16), I32(i32), I64(i64), I128(i128), U8(u8), U16(u16), U32(u32), U64(u64), U128(u128), F32(f32), F64(f64), Char(char), Str(Cow<'v, str>), Bytes(Cow<'v, [u8]>), Unit, Some, None, UnitStruct(&'static str), UnitVariant { name: &'static str, variant_index: u32, variant: &'static str, }, NewtypeStruct(&'static str), NewtypeVariant { name: &'static str, variant_index: u32, variant: &'static str, }, Seq(Option<usize>), Tuple(usize), TupleStruct { name: &'static str, len: usize, }, TupleVariant { name: &'static str, variant_index: u32, variant: &'static str, len: usize, }, Map(Option<usize>), Struct { name: &'static str, len: usize, }, StructVariant { name: &'static str, variant_index: u32, variant: &'static str, len: usize, },
}
Expand description

Value that corresponds to serde data model.

Primitive values, like numbers, will have the actual value copied, whilst for compound values, like structs, only metadata is available.

Variants§

§

Bool(bool)

bool value

§

I8(i8)

i8 value

§

I16(i16)

i16 value

§

I32(i32)

i32 value

§

I64(i64)

i64 value

§

I128(i128)

i128 value

§

U8(u8)

u8 value

§

U16(u16)

u16 value

§

U32(u32)

u32 value

§

U64(u64)

u64 value

§

U128(u128)

u128 value

§

F32(f32)

f32 value

§

F64(f64)

f64 value

§

Char(char)

char value

§

Str(Cow<'v, str>)

String value, borrowed or owned.

§

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

Bytes value, borrowed or owned.

Note that you need to use serde_bytes or do custom (de)serialization in order to get bytes value as a [u8] slice instead of a sequence.

§

Unit

Unit value, i.e. ().

§

Some

Metadata (marker) for a value of Option<T>::Some(...).

During serialization, the actual value contained in the Option is serialized in the follow up calls to the serializer. This metadata can thus be seen as a marker, telling that the actual value serialization will follow.

§

None

Metadata (marker) for a value of Option<T>::None.

§

UnitStruct(&'static str)

Metadata for a value of unit struct type (e.g. struct Unit).

Tuple Fields

§0: &'static str

Struct name, e.g. "Unit" in struct Unit.

§

UnitVariant

Metadata for a value of unit variant type (e.g. E::A in enum E { A, B }).

Fields

§name: &'static str

Enum name.

For example, this would be "E" in enum E { A, B }.

§variant_index: u32

Variant index in the enum.

For example, this would be 0 for E::A, 1 for E::B in enum E { A, B }.

Note that this is always a sequential index, not the numeric value assigned to the variant.

§variant: &'static str

Variant name.

For example, this would be "A" for E::A in enum E { A, B }.

§

NewtypeStruct(&'static str)

Metadata for a value of newtype struct (e.g. struct Millimeters(u8)).

Tuple Fields

§0: &'static str

Struct name, e.g. "Millimeters" in struct Millimeters(u8).

§

NewtypeVariant

Metadata for a value of unit variant type (e.g. E::N in enum E { N(u8) }).

Fields

§name: &'static str

Enum name.

For example, this would be "E" in enum E { N(u8) }.

§variant_index: u32

Variant index in the enum.

For example, this would be 0 for E::N in enum E { N(u8) }.

§variant: &'static str

Variant name.

For example, this would be "N" for E::N in enum E { N(u8) }.

§

Seq(Option<usize>)

Metadata for a value of sequence type (e.g. Vec<T> or HashSet<T>).

Tuple Fields

§0: Option<usize>

Length of the sequence, if known during (de)serialization.

§

Tuple(usize)

Metadata for a value of tuple type.

Tuple Fields

§0: usize

Tuple length.

Note that unlike Seq, the length is not optional and must be known during (de)serialization.

§

TupleStruct

Metadata for a value of tuple struct type (e.g. struct Rgb(u8, u8, u8)).

Fields

§name: &'static str

Struct name, e.g. "Rgb" in struct Rgb(u8, u8, u8).

§len: usize

Tuple length, e.g. 3 in struct Rgb(u8, u8, u8).

§

TupleVariant

Metadata for a value of tuple variant type (e.g. E::T in enum E { T(u8, u8) }).

Fields

§name: &'static str

Enum name.

For example, this would be "E" in enum E { T(u8, u8) }.

§variant_index: u32

Variant index in the enum.

For example, this would be 0 for E::T in enum E { T(u8, u8) }.

§variant: &'static str

Variant name.

For example, this would be "T" for E::T in enum E { T(u8, u8) }.

§len: usize

Tuple length, e.g. 2 for E::T in enum E { T(u8, u8) }.

§

Map(Option<usize>)

Metadata for a value of map type (e.g. BTreeMap<K, V>).

Tuple Fields

§0: Option<usize>

Number of map entries, if known during (de)serialization.

§

Struct

Metadata for a value of struct type (e.g. struct S { r: u8, g: u8, b: u8 }).

Fields

§name: &'static str

Struct name, e.g. "S" in struct S { r: u8, g: u8, b: u8 }.

§len: usize

Number of struct fields, e.g. 3 in struct S { r: u8, g: u8, b: u8 }.

Note that unlike Map, the number of fields must be known during (de)serialization.

Some (de)serializers do not distinguish between maps and structures, while some others do.

§

StructVariant

Metadata for a value of struct variant type (e.g. E::S in enum E { S { r: u8, g: u8, b: u8 } }).

Fields

§name: &'static str

Enum name.

For example, this would be "E" in enum E { S { r: u8, g: u8, b: u8 } }.

§variant_index: u32

Variant index in the enum.

For example, this would be 0 for E::S in enum E { S { r: u8, g: u8, b: u8 } }.

§variant: &'static str

Variant name.

For example, this would be "S" for E::S in enum E { S { r: u8, g: u8, b: u8 } }.

§len: usize

Number of struct fields, e.g. 3 for E::S in enum E { S { r: u8, g: u8, b: u8 } }.

Trait Implementations§

Source§

impl<'v> Clone for Value<'v>

Source§

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

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

Source§

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

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

impl Display for Value<'_>

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(value: &'v 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<'v> From<Cow<'v, [u8]>> for Value<'v>

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(value: Cow<'v, str>) -> 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<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<char> for Value<'_>

Source§

fn from(value: char) -> 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<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<i8> for Value<'_>

Source§

fn from(value: i8) -> 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 From<u8> for Value<'_>

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl<'v> PartialEq for Value<'v>

Source§

fn eq(&self, other: &Value<'v>) -> 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::Ok, S::Error>
where S: Serializer,

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

impl Eq for Value<'_>

Source§

impl<'v> StructuralPartialEq for Value<'v>

Auto Trait Implementations§

§

impl<'v> Freeze for Value<'v>

§

impl<'v> RefUnwindSafe for Value<'v>

§

impl<'v> Send for Value<'v>

§

impl<'v> Sync for Value<'v>

§

impl<'v> Unpin for Value<'v>

§

impl<'v> UnwindSafe for Value<'v>

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

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.