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>
impl ErrorAccumulator<Nil>
Source§impl<List> ErrorAccumulator<List>
impl<List> ErrorAccumulator<List>
Sourcepub fn field<FieldValue, E>(
self,
field: FieldName,
result: Result<FieldValue, E>,
) -> ErrorAccumulator<List::Output>
pub fn field<FieldValue, E>( self, field: FieldName, result: Result<FieldValue, E>, ) -> ErrorAccumulator<List::Output>
Record a result of parsing a field of the input.
Sourcepub fn field_builder<FieldValue>(
self,
field: FieldName,
) -> FieldBuilder<Self, FieldValue, Nil>where
List: Append<FieldValue>,
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.
Sourcepub fn strukt<StructValue>(
self,
field: FieldName,
) -> StructBuilder<Self, StructValue, Nil>where
List: Append<StructValue>,
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.
Sourcepub fn array<ElementValue>(
self,
field: FieldName,
) -> ArrayBuilder<Self, ElementValue>where
List: Append<Vec<ElementValue>>,
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.
Sourcepub 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,
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()
.
Sourcepub fn on_ok<C, Out>(
self,
constructor: C,
) -> ErrorAccumulatorFinisher<List, C, Out>where
List: ToTuple,
C: Constructor<List::List, Out>,
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.
Sourcepub fn analyse(self) -> Result<List::List, AccumulatedError>where
List: ToTuple,
pub fn analyse(self) -> Result<List::List, AccumulatedError>where
List: ToTuple,
Analyse all recorded results.
If at least one error was recorded the AccumulatedError
s are
returned else a tuple of all recorded Ok
values in recording order is
returned.