Diffstat (limited to 'src/build/builders/core/struct.rs')
| -rw-r--r-- | src/build/builders/core/struct.rs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs index cff1ab3..feada5d 100644 --- a/src/build/builders/core/struct.rs +++ b/src/build/builders/core/struct.rs @@ -34,9 +34,9 @@ pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static { type Seed: Send + Sync; - type FieldMarker: Send + Sync + Copy; + type FieldMarker: Send + Sync + Copy + core::fmt::Debug; - type Error: Send + Sync; + type Error: Send + Sync + core::fmt::Debug; type T: Send + Sync; @@ -53,13 +53,27 @@ pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static { fn marker_from_name(name: &str) -> Option<Self::FieldMarker>; } +pub struct StructError<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Effect> { + error: I::Error, +} + +impl<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Effect> core::fmt::Debug + for StructError<'ctx, I, M, E> +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("StructError") + .field("error", &self.error) + .finish() + } +} + impl<'ctx, I, M, E: Effect> BuilderTypes for StructBuilder<'ctx, I, M, E> where I: StructTypeInfo<'ctx, M, E>, { type Seed = I::Seed; - type Error = (); + type Error = StructError<'ctx, I, M, E>; type Value = I::T; } @@ -90,7 +104,7 @@ where E::wrap(async { match I::from_builders(self.builders).await { Ok(value) => Ok(value), - Err(_) => todo!(), + Err(err) => Err(StructError { error: err }), } }) } @@ -138,6 +152,7 @@ where I: StructTypeInfo<'ctx, M, E>, E: Effect, { + #[inline(always)] fn visit<'a>( &'a mut self, scope: DynSequenceScope<'a, 'ctx, E>, @@ -241,6 +256,7 @@ any_trait! { impl['ctx, I, M, E] NameVisitor<'ctx, I, M, E> = [ ValueProto<OwnedStatic<usize>, E>, ValueProto<TempBorrowedStaticHrt<str>, E>, + ValueProto<OwnedStatic<&'static str>, E>, ] where E: Effect, I: StructTypeInfo<'ctx, M, E>, @@ -283,3 +299,22 @@ where E::ready(VisitResult::Control(Flow::Done)) } } + +impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<&'static str>, E> for NameVisitor<'ctx, I, M, E> +where + E: Effect, + I: StructTypeInfo<'ctx, M, E>, +{ + fn visit<'a>( + &'a mut self, + OwnedStatic(name): TypeName::T<'a, 'ctx, OwnedStatic<&'static str>>, + ) -> Future<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>>>, E> + where + TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>>: Send + Sized, + 'ctx: 'a, + { + self.field_marker = I::marker_from_name(name); + + E::ready(VisitResult::Control(Flow::Done)) + } +} |