Skip to main content

Kind

Enum Kind 

Source
#[non_exhaustive]
pub enum Kind {
Show 14 variants Null, Bool(bool), U64(u64), I64(i64), F32(f32), F64(f64), Char(char), Str(String), Lexical(String), Bytes(Bytes<'static>), Ext(ExtValue<'static>), Implicit(Implicit<'static>), Seq(Seq), Map(Map),
}
Expand description

The data of a Value.

See Value for more information.

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

Null

§

Bool(bool)

§

U64(u64)

An unsigned integer.

§

I64(i64)

A signed integer.

Values created by this crate only use this for negative integers.

§

F32(f32)

A single precision float.

It keeps the precision for serialization (0.1f32 is written as 0.1), otherwise it behaves like the same value as F64: they compare equal and hash the same.

§

F64(f64)

A double precision float.

§

Char(char)

§

Str(String)

§

Lexical(String)

The lexical form of a value whose type the format cannot express.

This is created from Atom::Lexical, for instance for the keys of JSON objects. It’s serialized as lexical atom again, so types that parse lexical atoms (like numbers) can be deserialized from it. Otherwise it behaves like a string: it compares equal to and hashes like the same Str and the accessors for strings return it.

§

Bytes(Bytes<'static>)

§

Ext(ExtValue<'static>)

A value extending the data model.

§

Implicit(Implicit<'static>)

A value whose type the format inferred from its text.

This is created from Atom::Implicit, for instance for the plain scalars of YAML (42, 1.10, true or ~). It’s serialized as implicit atom again, so types that do not accept the value (like strings) can be deserialized from its text. Otherwise it behaves like its value: it compares equal to and hashes like the same value, the accessors (like as_f64) return it and as_str does not return the text.

§

Seq(Seq)

§

Map(Map)

Implementations§

Source§

impl Kind

Source

pub fn name(&self) -> &str

Returns the human readable name of the kind.

Source

pub fn is_null(&self) -> bool

Returns true if this is null.

Extension values that fall back to null count as null.

Source

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

Returns the value of a bool.

Source

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

Returns the value of an integer if it fits into u64.

Source

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

Returns the value of an integer if it fits into i64.

Source

pub fn as_u128(&self) -> Option<u128>

Returns the value of an integer if it fits into u128.

Source

pub fn as_i128(&self) -> Option<i128>

Returns the value of an integer if it fits into i128.

Source

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

Returns the value of a number as f64.

Integers are converted, which can lose precision.

Source

pub fn as_char(&self) -> Option<char>

Returns the value of a char.

Source

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

Returns the value of a string.

For extension values this returns the fallback if it’s a string that borrows from the value.

Source

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

Returns the data of bytes.

Source

pub fn as_seq(&self) -> Option<&Seq>

Returns the sequence.

Source

pub fn as_seq_mut(&mut self) -> Option<&mut Seq>

Returns the sequence mutably.

Source

pub fn as_map(&self) -> Option<&Map>

Returns the map.

Source

pub fn as_map_mut(&mut self) -> Option<&mut Map>

Returns the map mutably.

Source

pub fn as_ext(&self) -> Option<&ExtValue<'static>>

Returns the extension value.

Source

pub fn downcast_ext<T: Extension>(&self) -> Option<&T>

Returns the extension value if it’s of type T.

For extensions that borrow, use downcast_ext_value.

Source

pub fn downcast_ext_value<K: BorrowedExtension>(&self) -> Option<&K::Value<'_>>

Returns the extension value if it’s of the extension with the key K.

See BorrowedExtension.

use deser::ext::Number;
use deser_value::Value;

let value: Value =
    deser_json::from_str("0.10000000000000000001").unwrap();
let number = value.downcast_ext_value::<Number>().unwrap();
assert_eq!(number.as_str(), "0.10000000000000000001");
Source

pub fn is_str(&self) -> bool

Returns true if this is a string.

This is also true for lexical values.

Source

pub fn is_lexical(&self) -> bool

Returns true if this is a lexical value.

Source

pub fn is_seq(&self) -> bool

Returns true if this is a sequence.

Source

pub fn is_map(&self) -> bool

Returns true if this is a map.

Source

pub fn get<I: ValueIndex>(&self, index: I) -> Option<&Value>

Looks up a value in a sequence (by index) or a map (by key).

use deser_value::value;

let value = value!({"items": [1, 2], 42: "answer"});
assert_eq!(value.get("items").and_then(|x| x.get(1)), Some(&value!(2)));
assert_eq!(value.get(&value!(42)), Some(&value!("answer")));
assert_eq!(value.get("missing"), None);
Source

pub fn get_mut<I: ValueIndex>(&mut self, index: I) -> Option<&mut Value>

Looks up a value in a sequence (by index) or a map (by key) mutably.

Trait Implementations§

Source§

impl Clone for Kind

Source§

fn clone(&self) -> Kind

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 Kind

Source§

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

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

impl Eq for Kind

Source§

impl From<Kind> for Value

Source§

fn from(kind: Kind) -> Value

Converts to this type from the input type.
Source§

impl Hash for Kind

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Kind

Source§

fn eq(&self, other: &Kind) -> 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 Kind

Source§

fn serialize(&self, state: &mut State) -> Result<Chunk<'_>, Error>

Serializes this serializable.
Source§

fn container_shape(&self) -> ContainerShape

Returns the shape of this value if it’s a map or sequence. Read more
Source§

fn is_optional(&self) -> bool

Checks if the current value that would be serialized represents an optional value. Read more
Source§

fn finish(&self, _state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn describe(&self, d: &mut dyn Describe)

Describes the Rust shape of this value. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Kind

§

impl !UnwindSafe for Kind

§

impl Freeze for Kind

§

impl Send for Kind

§

impl Sync for Kind

§

impl Unpin for Kind

§

impl UnsafeUnpin for Kind

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.