pub struct Implicit<'a> { /* private fields */ }Expand description
A value whose type the format inferred from its text.
Some formats write values as text and infer their type from it: in YAML
42 is an integer, 1.10 a float, true a boolean and ~ null, but
only because these plain scalars look like it. The format resolves the
value with its own rules (which are not the ones of Rust, 0x1F is an
integer in YAML) and emits it together with its text.
Types that accept the value receive it, types that reject it receive
the text as Str instead (see
default_atom). This
means that a u32 is 31 for 0x1F while a String is "0x1F" and an
Option<String> is None for ~ while a String is "~". If both are
rejected, the error is the one of the value. Enums look up their
variants by the value and then by the text. Types that take any value
(like dynamic values) keep both. Serializers write the text if it’s
the same value in their format (1.10 stays 1.10 in JSON and YAML,
0x1F stays 0x1F in YAML), otherwise they write the value.
use deser::{Atom, Implicit, ImplicitValue};
let atom = Atom::Implicit(Implicit::new("0x1F", ImplicitValue::U64(31)));
let mut out = None::<u32>;
deser::de::DeserializeDriver::new(&mut out).emit(atom.clone()).unwrap();
assert_eq!(out, Some(31));
let mut out = None::<String>;
deser::de::DeserializeDriver::new(&mut out).emit(atom).unwrap();
assert_eq!(out.as_deref(), Some("0x1F"));Implementations§
Source§impl<'a> Implicit<'a>
impl<'a> Implicit<'a>
Sourcepub fn new<T: Into<Text<'a>>>(text: T, value: ImplicitValue) -> Implicit<'a>
pub fn new<T: Into<Text<'a>>>(text: T, value: ImplicitValue) -> Implicit<'a>
Creates a value from its text and the value inferred from it.
Sourcepub fn value(&self) -> ImplicitValue
pub fn value(&self) -> ImplicitValue
Returns the inferred value.
Sourcepub fn into_parts(self) -> (Text<'a>, ImplicitValue)
pub fn into_parts(self) -> (Text<'a>, ImplicitValue)
Splits the value into its text and the inferred value.
Sourcepub fn as_borrowed(&self) -> Implicit<'_>
pub fn as_borrowed(&self) -> Implicit<'_>
Returns a value borrowing from this one.