use std::marker::PhantomData;
use crate::{AccumulatedError, Constructor, cons::ToTuple};
mod array;
mod field;
mod strukt;
pub use self::{array::ArrayBuilder, field::FieldBuilder, strukt::StructBuilder};
pub trait ErrorBuilderParent<T> {
type AfterRecord;
fn finish_child_builder(self, child_result: Result<T, AccumulatedError>) -> Self::AfterRecord;
}
#[derive(Debug)]
pub struct BuilderFinisher<Parent, Out, List, Constructor> {
parent: Parent,
accumulated_errors: AccumulatedError,
values: List,
constructor: Constructor,
_marker: PhantomData<Out>,
}
impl<Parent, Value, List, C> BuilderFinisher<Parent, Value, List, C>
where
Parent: ErrorBuilderParent<Value>,
List: ToTuple,
C: Constructor<List::List, Value>,
{
pub fn finish(self) -> Parent::AfterRecord {
let result = if self.accumulated_errors.is_empty() {
Ok(self.constructor.construct(self.values.unwrap_tuple()))
} else {
Err(self.accumulated_errors)
};
self.parent.finish_child_builder(result)
}
}