ErrorAccumulator

Struct ErrorAccumulator 

Source
pub struct ErrorAccumulator<List> { /* private fields */ }
Expand description

The entry-point to accumulate parsing results.

All parsing results are tracked, i.e. Ok values and errors alike.

Use the methods like field(), strukt(), or array() to tell the accumulator from where in the input the next parsing results are derived.

The final analyse() call returns all errors if at least one error was recorded else a tuple of all recorded Ok values is returned. There is also on_ok() to convert the recorded Ok values before retruning the tuple.

Implementations§

Source§

impl ErrorAccumulator<Nil>

Source

pub fn new() -> Self

Create a new, empty ErrorAccumulator.

Source§

impl<List> ErrorAccumulator<List>

Source

pub fn field<FieldValue, E>( self, field: FieldName, result: Result<FieldValue, E>, ) -> ErrorAccumulator<List::Output>
where List: Append<FieldValue>, E: Error + Send + Sync + 'static,

Record a result of parsing a field of the input.

Source

pub fn field_builder<FieldValue>( self, field: FieldName, ) -> FieldBuilder<Self, FieldValue, Nil>
where List: Append<FieldValue>,

Start a FieldBuilder to record results for parsing of a single input field.

This allows for more finegrained validation of a single input value, e.g. like testing for different properties.

See FieldBuilder for more information.

Source

pub fn strukt<StructValue>( self, field: FieldName, ) -> StructBuilder<Self, StructValue, Nil>
where List: Append<StructValue>,

Start a StructBuilder to analyse the parsing results of a nested struct of the input.

This is mainly to record the correct source paths when walking the input’s structure.

See StructBuilder for more information.

Source

pub fn array<ElementValue>( self, field: FieldName, ) -> ArrayBuilder<Self, ElementValue>
where List: Append<Vec<ElementValue>>,

Start an ArrayBuilder to analyse the elements of a nested array of the input.

See ArrayBuilder for more information.

Source

pub fn with_previous<Valid, T, E>( self, validator: Valid, ) -> ErrorAccumulator<List::Output>
where Valid: ListValidator<List, T, E>, List: AsRefTuple + Append<T>, E: Error + Send + Sync + 'static,

Run another validation step on the previously recorded Ok values if there were no errors yet.

In case an error was already recorded the validator is not executed.

For an example, see the docs of StructBuilder::with_previous().

Source

pub fn on_ok<C, Out>( self, constructor: C, ) -> ErrorAccumulatorFinisher<List, C, Out>
where List: ToTuple, C: Constructor<List::List, Out>,

Provide a Constructor function that is called on analyse() in case all recorded results (including nested results) where Ok.

  • The input to the constructor are the recorded Ok values in order of recording.
  • After providing the constructor no more results can be recorded.
Source

pub fn analyse(self) -> Result<List::List, AccumulatedError>
where List: ToTuple,

Analyse all recorded results.

If at least one error was recorded the AccumulatedErrors are returned else a tuple of all recorded Ok values in recording order is returned.

Trait Implementations§

Source§

impl<List: Debug> Debug for ErrorAccumulator<List>

Source§

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

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

impl Default for ErrorAccumulator<Nil>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<ChildValue, List> ErrorBuilderParent<ChildValue> for ErrorAccumulator<List>
where List: Append<ChildValue>,

Source§

type AfterRecord = ErrorAccumulator<<List as Append<ChildValue>>::Output>

The parent builder after the child builder finished. Read more
Source§

fn finish_child_builder( self, child_result: Result<ChildValue, AccumulatedError>, ) -> Self::AfterRecord

Record the final result of the child builder.

Auto Trait Implementations§

§

impl<List> Freeze for ErrorAccumulator<List>
where List: Freeze,

§

impl<List> !RefUnwindSafe for ErrorAccumulator<List>

§

impl<List> Send for ErrorAccumulator<List>
where List: Send,

§

impl<List> Sync for ErrorAccumulator<List>
where List: Sync,

§

impl<List> Unpin for ErrorAccumulator<List>
where List: Unpin,

§

impl<List> !UnwindSafe for ErrorAccumulator<List>

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.