Skip to main content

Context

Struct Context 

Source
pub struct Context<'de> {
    pub arena: &'de Arena,
    pub errors: Vec<Error>,
    /* private fields */
}
Available on crate feature from-toml only.
Expand description

Shared state that accumulates errors and holds the arena.

Created by parse and stored inside Document. Pass it into TableHelper::new or Item::table_helper when implementing FromToml.

Multiple errors can be recorded during a single conversion pass. Inspect them via Document::errors.

Fields§

§arena: &'de Arena§errors: Vec<Error>

Implementations§

Source§

impl<'de> Context<'de>

Source

pub fn source(&self) -> &'de str

Returns the original TOML source string passed to parse.

Source

pub fn report_expected_but_found( &mut self, message: &'static &'static str, found: &Item<'de>, ) -> Failed

Records a “expected X, found Y” type-mismatch error and returns Failed.

Source

pub fn report_unexpected_variant( &mut self, expected: &'static [&'static str], found: &Item<'de>, ) -> Failed

Records an “unknown variant” error listing the accepted variants and returns Failed.

Source

pub fn report_error_at(&mut self, message: &'static str, at: Span) -> Failed

Records a custom error message at the given span and returns Failed.

Source

pub fn push_error(&mut self, error: Error) -> Failed

Pushes a pre-built Error and returns Failed.

Source

pub fn report_custom_error( &mut self, error: impl ToString, item: &Item<'de>, ) -> Failed

Records a custom error from a ToString value and returns Failed.

Source

pub fn report_out_of_range( &mut self, ty: &'static &'static str, range: &'static &'static str, found: &Item<'de>, ) -> Failed

Records an out-of-range error for the type name and returns Failed.

Source

pub fn report_missing_field( &mut self, name: &'static str, item: &Item<'de>, ) -> Failed

Records a missing-field error and returns Failed.

Used by generated FromToml implementations that iterate over table entries instead of using TableHelper.

Source

pub fn report_duplicate_field( &mut self, name: &'static str, key_span: Span, first_key_span: Span, item: &Item<'de>, ) -> Failed

Records a duplicate-field error and returns Failed.

Used by generated FromToml implementations when a field with aliases is set more than once (e.g. both the primary key and an alias appear).

Source

pub fn report_deprecated_field( &mut self, tag: u32, old: &'static &'static str, new: &'static &'static str, key_span: Span, item: &Item<'de>, )

Records a deprecated-field warning with TOML path information.

Unlike other report_* methods this is non-fatal: it pushes an error but does not return Failed, so deserialization continues.

Source

pub fn report_unexpected_key( &mut self, tag: u32, item: &Item<'de>, key_span: Span, ) -> Failed

Records an unexpected-key error with TOML path information.

Auto Trait Implementations§

§

impl<'de> Freeze for Context<'de>

§

impl<'de> !RefUnwindSafe for Context<'de>

§

impl<'de> !Send for Context<'de>

§

impl<'de> !Sync for Context<'de>

§

impl<'de> Unpin for Context<'de>

§

impl<'de> UnsafeUnpin for Context<'de>

§

impl<'de> !UnwindSafe for Context<'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>,

Source§

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

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.