#[non_exhaustive]pub enum Kind {
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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
impl Kind
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true if this is null.
Extension values that fall back to null count as null.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the value of a number as f64.
Integers are converted, which can lose precision.
Sourcepub fn as_str(&self) -> Option<&str>
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.
Sourcepub fn as_seq_mut(&mut self) -> Option<&mut Seq>
pub fn as_seq_mut(&mut self) -> Option<&mut Seq>
Returns the sequence mutably.
Sourcepub fn as_map_mut(&mut self) -> Option<&mut Map>
pub fn as_map_mut(&mut self) -> Option<&mut Map>
Returns the map mutably.
Sourcepub fn downcast_ext<T: Extension>(&self) -> Option<&T>
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.
Sourcepub fn downcast_ext_value<K: BorrowedExtension>(&self) -> Option<&K::Value<'_>>
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");Sourcepub fn is_str(&self) -> bool
pub fn is_str(&self) -> bool
Returns true if this is a string.
This is also true for lexical values.
Sourcepub fn is_lexical(&self) -> bool
pub fn is_lexical(&self) -> bool
Returns true if this is a lexical value.
Sourcepub fn get<I: ValueIndex>(&self, index: I) -> Option<&Value>
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);Sourcepub fn get_mut<I: ValueIndex>(&mut self, index: I) -> Option<&mut Value>
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§
impl Eq for Kind
Source§impl Serialize for Kind
impl Serialize for Kind
Source§fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(this: &'a Self, state: &mut State) -> Result<Emit<'a>, Error>
Source§fn container_shape(value: &Self) -> ContainerShape
fn container_shape(value: &Self) -> ContainerShape
Source§fn is_optional(value: &Self) -> bool
fn is_optional(value: &Self) -> bool
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.