Struct toml_span::de_helpers::TableHelper

source ·
pub struct TableHelper<'de> {
    pub table: Table<'de>,
    pub errors: Vec<Error>,
    /* private fields */
}
Expand description

A helper for dealing with ValueInner::Table

Fields§

§table: Table<'de>

The table the helper is operating upon

§errors: Vec<Error>

The errors accumulated while deserializing

Implementations§

source§

impl<'de> TableHelper<'de>

source

pub fn new(value: &mut Value<'de>) -> Result<Self, DeserError>

Creates a helper for the value, failing if it is not a table

source

pub fn contains(&self, name: &'de str) -> bool

Returns true if the table contains the specified key

source

pub fn take(&mut self, name: &'static str) -> Option<(Key<'de>, Value<'de>)>

Takes the specified key and its value if it exists

source

pub fn required<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Result<T, Error>

Attempts to deserialize the specified key

Errors that occur when calling this method are automatically added to the set of errors that are reported from Self::finalize, so not early returning if this method fails will still report the error by default

§Errors
  • The key does not exist
  • The Deserialize implementation for the type returns an error
source

pub fn required_s<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Result<Spanned<T>, Error>

The same as Self::required, except it returns a Spanned

source

pub fn optional<T: Deserialize<'de>>(&mut self, name: &'static str) -> Option<T>

Attempts to deserialize the specified key, if it exists

Note that if the key exists but deserialization fails, an error will be appended and if Self::finalize is called it will return that error along with any others that occurred

source

pub fn optional_s<T: Deserialize<'de>>( &mut self, name: &'static str, ) -> Option<Spanned<T>>

The same as Self::optional, except it returns a Spanned

source

pub fn finalize( self, original: Option<&mut Value<'de>>, ) -> Result<(), DeserError>

Called when you are finished with this TableHelper

If errors have been accumulated when using this TableHelper, this will return an error with all of those errors.

Additionally, if Option::None is passed, any keys that still exist in the table will be added to an ErrorKind::UnexpectedKeys error, which can be considered equivalent to #[serde(deny_unknown_fields)]

If you want simulate #[serde(flatten)] you can instead put that table back in its original value during this step

Trait Implementations§

source§

impl<'de> From<(BTreeMap<Key<'de>, Value<'de>>, Span)> for TableHelper<'de>

source§

fn from((table, span): (Table<'de>, Span)) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'de> Freeze for TableHelper<'de>

§

impl<'de> RefUnwindSafe for TableHelper<'de>

§

impl<'de> Send for TableHelper<'de>

§

impl<'de> Sync for TableHelper<'de>

§

impl<'de> Unpin for TableHelper<'de>

§

impl<'de> UnwindSafe for TableHelper<'de>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.