StructBuilder

Struct StructBuilder 

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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");
Source

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.

Trait Implementations§

Source§

impl<Parent: Debug, Value: Debug, List: Debug> Debug for StructBuilder<Parent, Value, List>

Source§

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

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

impl<Parent, OwnValue, ChildValue, List> ErrorBuilderParent<ChildValue> for StructBuilder<Parent, OwnValue, List>
where List: Append<ChildValue>,

Source§

type AfterRecord = StructBuilder<Parent, OwnValue, <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<Parent, Value, List> Freeze for StructBuilder<Parent, Value, List>
where Parent: Freeze, List: Freeze,

§

impl<Parent, Value, List> !RefUnwindSafe for StructBuilder<Parent, Value, List>

§

impl<Parent, Value, List> Send for StructBuilder<Parent, Value, List>
where Parent: Send, List: Send, Value: Send,

§

impl<Parent, Value, List> Sync for StructBuilder<Parent, Value, List>
where Parent: Sync, List: Sync, Value: Sync,

§

impl<Parent, Value, List> Unpin for StructBuilder<Parent, Value, List>
where Parent: Unpin, List: Unpin, Value: Unpin,

§

impl<Parent, Value, List> !UnwindSafe for StructBuilder<Parent, Value, 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.