Diffstat (limited to 'src/build/builders/core/struct.rs')
| -rw-r--r-- | src/build/builders/core/struct.rs | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs index e011eff..9ee98aa 100644 --- a/src/build/builders/core/struct.rs +++ b/src/build/builders/core/struct.rs @@ -24,20 +24,20 @@ use super::NoopVisitor; /// A builder for a struct. pub struct StructBuilder<'ctx, Info, Mode, E: Effect> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { inner: Inner<'ctx, Info, Mode, E>, } enum Inner<'ctx, Info, Mode, E: Effect> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { Temp, Seed(Info::Seed), Builders { /// The builders for all the struct's fields. - builders: Info::Builders<E>, + builders: Info::Builders, /// The kind of struct the builder is expecting. kind: StructKind, @@ -61,9 +61,9 @@ enum StructKind { /// /// The `Mode` generic allows implementations to change depending on the mode the user gives. /// It is not used by the trait directly. -pub trait StructTypeInfo<'ctx, Mode>: 'static { +pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Effect>: 'static { /// A struct of builders for each field. - type Builders<E: Effect>: Ss; + type Builders: Ss; /// The seed value needed to make the builders. type Seed: Ss; @@ -85,19 +85,19 @@ pub trait StructTypeInfo<'ctx, Mode>: 'static { const FIELD_COUNT: usize; /// Create a set of builders from a seed value. - fn new_builders<'a, E: Effect>(seed: Self::Seed) -> ErasedEffective<'a, Self::Builders<E>, E>; + fn new_builders<'a>(seed: Self::Seed) -> ErasedEffective<'a, Self::Builders, E>; /// Finish building the struct value. - fn from_builders<'a, E: Effect>( - builders: Self::Builders<E>, + fn from_builders<'a>( + builders: Self::Builders, ) -> ErasedEffective<'a, Result<Self::T, Self::Error>, E>; /// Get the visitor for a field. /// /// This is how [`StructBuilder`] picks a field builder to use. - fn as_visitor<'a, E: Effect>( + fn as_visitor<'a>( marker: Self::FieldMarker, - builders: &'a mut Self::Builders<E>, + builders: &'a mut Self::Builders, ) -> DynVisitor<'a, 'ctx>; /// Get a field marker from the index of the field. @@ -113,35 +113,35 @@ pub trait StructTypeInfo<'ctx, Mode>: 'static { } /// Error that [`StructBuilder`] returns. -pub struct StructError<'ctx, Info, M> +pub struct StructError<'ctx, Info, M, E: Effect> where - Info: StructTypeInfo<'ctx, M>, + Info: StructTypeInfo<'ctx, M, E>, { /// Error from the struct info definition. error: Info::Error, } -impl<'ctx, Info, Mode> StructError<'ctx, Info, Mode> +impl<'ctx, Info, Mode, E: Effect> StructError<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { fn from_field_err(error: Info::Error) -> Self { Self { error } } } -impl<'ctx, Info, Mode> Debug for StructError<'ctx, Info, Mode> +impl<'ctx, Info, Mode, E: Effect> Debug for StructError<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("StructError").field(&self.error).finish() } } -impl<'ctx, Info, Mode> Display for StructError<'ctx, Info, Mode> +impl<'ctx, Info, Mode, E: Effect> Display for StructError<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { Display::fmt(&self.error, f) @@ -150,25 +150,25 @@ where impl<'ctx, Info, Mode, E: Effect> BuilderTypes for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { type Seed = Info::Seed; - type Error = StructError<'ctx, Info, Mode>; + type Error = StructError<'ctx, Info, Mode, E>; type Value = Info::T; } impl<'ctx, Info, Mode: 'ctx, E: Effect> StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { fn make_builders<'e>(&'e mut self) -> ErasedEffective<'e, (), E> where 'ctx: 'e, { match core::mem::replace(&mut self.inner, Inner::Temp) { - Inner::Seed(seed) => Info::new_builders::<E>(seed).map(|builders| { + Inner::Seed(seed) => Info::new_builders(seed).map(|builders| { self.inner = Inner::Builders { builders, kind: StructKind::Tuple, @@ -185,7 +185,7 @@ where impl<'ctx, Info, Mode: 'ctx, E: Effect> Builder<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, { fn from_seed<'a>(seed: Self::Seed) -> ErasedEffective<'a, Self, E> where @@ -205,7 +205,7 @@ where Inner::Temp => unreachable!(), Inner::Seed(seed) => { // We may be able to make a value from just the seed. - Info::new_builders::<E>(seed) + Info::new_builders(seed) .then(|builders| Info::from_builders(builders)) .map(|result| result.map_err(StructError::from_field_err)) } @@ -233,13 +233,13 @@ any_trait! { SequenceProto<E> ] where E: Effect, - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, Mode: 'ctx, } impl<'ctx, Info, Mode: 'ctx, E> RequestHint<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, E: Effect, { #[inline(always)] @@ -250,12 +250,12 @@ where E::as_ctx((self, walker), |(this, walker)| { // Start with a hint to use the value protocol to directly transfer the // struct value. - hint_protocol::<ValueProto<Info::ValueT, E>, _>(walker.cast(), *this, ()).cast() + hint_protocol::<ValueProto<Info::ValueT, E>>(walker.cast(), *this, ()).cast() }) .if_not_finished(|(this, walker)| { // Next hint that the struct protocol should be used to switch into // map-like if the walker supports it. - hint_protocol::<TagProto<tags::Struct, E>, _>( + hint_protocol::<TagProto<tags::Struct, E>>( walker.cast(), *this, TagHint { kind: TagConst }, @@ -266,7 +266,7 @@ where // If the struct hint didn't work, // then hint that the map protocol should be used to switch into // map-like if the walker supports it. - hint_protocol::<TagProto<tags::Map, E>, _>( + hint_protocol::<TagProto<tags::Map, E>>( walker.cast(), *this, TagHint { kind: TagConst }, @@ -276,7 +276,7 @@ where .if_not_finished(|(this, walker)| { // Lastly hint to use a sequence to get the field values. // We hint with the exact number of fields we are expecting. - hint_protocol::<SequenceProto<E>, _>( + hint_protocol::<SequenceProto<E>>( walker.cast(), *this, SequenceHint { @@ -297,7 +297,7 @@ where /// This skips needing to go through each field individually. impl<'ctx, Info, Mode, E> Value<'ctx, Info::ValueT, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, E: Effect, { fn visit<'a>( @@ -321,7 +321,7 @@ where /// By default [`StructBuilder`] expects a tuple-like struct. impl<'ctx, Info, Mode: 'ctx, E> Tag<'ctx, tags::Struct, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, E: Effect, { fn visit<'this: 'e, 'walker: 'e, 'e>( @@ -347,7 +347,7 @@ where /// By default [`StructBuilder`] expects a tuple-like struct. impl<'ctx, Info, Mode: 'ctx, E> Tag<'ctx, tags::Map, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, E: Effect, { fn visit<'this: 'e, 'walker: 'e, 'e>( @@ -376,7 +376,7 @@ where /// a sequence of key value pairs. Where the key is the field name. impl<'ctx, Info, Mode: 'ctx, E> Sequence<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where - Info: StructTypeInfo<'ctx, Mode>, + Info: StructTypeInfo<'ctx, Mode, E>, E: Effect, { fn visit<'a: 'c, 'b: 'c, 'c>( @@ -448,8 +448,8 @@ where } } -struct FieldVisitor<'a, 'ctx, I: StructTypeInfo<'ctx, M>, M, E: Effect> { - builders: &'a mut I::Builders<E>, +struct FieldVisitor<'a, 'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Effect> { + builders: &'a mut I::Builders, marker: Option<I::FieldMarker>, _marker: Marker<E>, } @@ -468,13 +468,13 @@ any_trait! { }) } where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, } impl<'d, 'ctx, I, M, E> Tag<'ctx, tags::Key, E> for FieldVisitor<'d, 'ctx, I, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, { fn visit<'a: 'c, 'b: 'c, 'c>( &'a mut self, @@ -495,7 +495,7 @@ where } } -struct NameVisitor<'ctx, I: StructTypeInfo<'ctx, M>, M, E: Effect> { +struct NameVisitor<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Effect> { field_marker: Option<I::FieldMarker>, _marker: Marker<E>, } @@ -507,13 +507,13 @@ any_trait! { ValueProto<OwnedStatic<&'static str>, E>, ] where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, } impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<usize>, E> for NameVisitor<'ctx, I, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, { fn visit<'a>( &'a mut self, @@ -532,7 +532,7 @@ where impl<'ctx, I, M, E> Value<'ctx, TempBorrowedStaticHrt<str>, E> for NameVisitor<'ctx, I, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, { fn visit<'a>( &'a mut self, @@ -551,7 +551,7 @@ where impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<&'static str>, E> for NameVisitor<'ctx, I, M, E> where E: Effect, - I: StructTypeInfo<'ctx, M>, + I: StructTypeInfo<'ctx, M, E>, { fn visit<'a>( &'a mut self, |