Skip to main content

Implicit

Struct Implicit 

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

Source

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.

Source

pub fn text(&self) -> &Text<'a>

Returns the text of the value.

Source

pub fn value(&self) -> ImplicitValue

Returns the inferred value.

Source

pub fn into_parts(self) -> (Text<'a>, ImplicitValue)

Splits the value into its text and the inferred value.

Source

pub fn as_borrowed(&self) -> Implicit<'_>

Returns a value borrowing from this one.

Source

pub fn to_static(&self) -> Implicit<'static>

Makes a static clone decoupling the lifetimes.

Trait Implementations§

Source§

impl<'a> Clone for Implicit<'a>

Source§

fn clone(&self) -> Self

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 Implicit<'_>

Source§

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

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

impl PartialEq for Implicit<'_>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Implicit<'a>

§

impl<'a> RefUnwindSafe for Implicit<'a>

§

impl<'a> Send for Implicit<'a>

§

impl<'a> Sync for Implicit<'a>

§

impl<'a> Unpin for Implicit<'a>

§

impl<'a> UnsafeUnpin for Implicit<'a>

§

impl<'a> UnwindSafe for Implicit<'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, 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, 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.