pub struct StructBuilder<Parent, Value, List> { /* private fields */ }
Expand description
A builder to record parsing results for a nested struct in the input.
A StructBuilder
can have other nested structs, arrays, and fields.
Implementations§
Source§impl<Parent, Value, List> StructBuilder<Parent, Value, List>where
Parent: ErrorBuilderParent<Value>,
impl<Parent, Value, List> StructBuilder<Parent, Value, List>where
Parent: ErrorBuilderParent<Value>,
Sourcepub fn field<T, E>(
self,
field: FieldName,
result: Result<T, E>,
) -> StructBuilder<Parent, Value, List::Output>where
List: Append<T>,
E: Error + Send + Sync + 'static,
Self: ErrorBuilderParent<T, AfterRecord = StructBuilder<Parent, Value, List::Output>>,
pub fn field<T, E>(
self,
field: FieldName,
result: Result<T, E>,
) -> StructBuilder<Parent, Value, List::Output>where
List: Append<T>,
E: Error + Send + Sync + 'static,
Self: ErrorBuilderParent<T, AfterRecord = StructBuilder<Parent, Value, List::Output>>,
Record a parsing result for a field in this struct.
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 the parsing results for a field in
this struct.
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 record the parsing results of a nested
struct within the current one.
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 record the parsing results for a nested
array within the current struct.
Sourcepub fn with_previous<Valid, T, E>(
self,
validator: Valid,
) -> StructBuilder<Parent, Value, 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,
) -> StructBuilder<Parent, Value, 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.
There are blanked implementations for ListValidator
for closures
that take the references to Ok
values as arguments, e.g.
let res = ErrorAccumulator::new().strukt(FOO)
.field(BAR, NonZeroU16::try_from(16))
.field(BAZ, NonZeroU16::try_from(8))
// for some reason the type annotation with `&_` is required to make this compile
.with_previous(|bar: &_, baz: &_|
Ok::<_, Infallible>(format!("{bar}{baz}"))
)
.on_ok(|_, _, res| res)
.finish()
.analyse()
.unwrap()
.0;
assert_eq!(res.as_str(), "168");
Sourcepub fn on_ok<C>(self, constructor: C) -> BuilderFinisher<Parent, Value, List, C>where
List: ToTuple,
C: Constructor<List::List, Value>,
pub fn on_ok<C>(self, constructor: C) -> BuilderFinisher<Parent, Value, List, C>where
List: ToTuple,
C: Constructor<List::List, Value>,
Provide a Constructor
to build a struct values from all the recorded
Ok
values of the builder.