Diffstat (limited to 'src/build/builders/core/struct.rs')
| -rw-r--r-- | src/build/builders/core/struct.rs | 84 |
1 files changed, 68 insertions, 16 deletions
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs index f874fac..d08d06e 100644 --- a/src/build/builders/core/struct.rs +++ b/src/build/builders/core/struct.rs @@ -1,7 +1,7 @@ use core::fmt::{Debug, Display}; use effectful::{ - bound::{IsSend, IsSync}, + bound::{IsSend, IsSync, Dynamic}, effective::Effective, environment::{DynBind, Environment, NativeForm}, higher_ranked::Mut, @@ -50,7 +50,7 @@ where /// The kind of struct the builder is expecting. kind: StructKind, }, - Value(Info::T), + Value(Dynamic<Info::T>), } /// Structs are either tuple-like or map-like. @@ -70,7 +70,8 @@ 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: 'ctx, E: Environment>: 'static { +pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static +{ /// A struct of builders for each field. type Builders: DynBind<E>; @@ -89,7 +90,7 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static { type ValueT: TypeName::MemberType<E>; /// The struct type this info is for. - type T: DynBind<E>; + type T; const FIELD_COUNT: usize; @@ -99,7 +100,9 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static { /// Finish building the struct value. fn from_builders<'a>( builders: Self::Builders, - ) -> NativeForm<'a, Result<Self::T, Self::Error>, E>; + ) -> NativeForm<'a, Result<Dynamic<Self::T>, Self::Error>, E> + where + Dynamic<Self::T>: DynBind<E>; /// Get the visitor for a field. /// @@ -161,12 +164,19 @@ where impl<'ctx, Info, Mode, E: Environment> BuilderTypes<E> for StructBuilder<'ctx, Info, Mode, E> where Info: StructTypeInfo<'ctx, Mode, E>, + Dynamic<Info::T>: DynBind<E> { type Seed = Info::Seed; type Error = StructError<'ctx, Info, Mode, E>; + type Output = Dynamic<Info::T>; + type Value = Info::T; + + fn unwrap_output(output: Self::Output) -> Self::Value { + output.0 + } } impl<'ctx, Info, Mode: 'ctx, E: Environment> StructBuilder<'ctx, Info, Mode, E> @@ -200,7 +210,14 @@ impl<'ctx, Info, Mode: 'ctx, E: Environment> Builder<'ctx, E> for StructBuilder< where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, - for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, + Dynamic<Info::T>: DynBind<E>, + Info: StructTypeInfo<'ctx, Mode, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + for<'a> Dynamic<&'a Info::T>: DynBind<E>, + for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, { fn from_seed<'a>(seed: Self::Seed) -> NativeForm<'a, Self, E> where @@ -212,7 +229,7 @@ where .cast() } - fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E> + fn build<'a>(self) -> NativeForm<'a, Result<Self::Output, Self::Error>, E> where Self: 'a, { @@ -242,7 +259,14 @@ impl<'ctx, Info, Mode: 'ctx, E: Environment> AsVisitor<'ctx, E> where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, - for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, + Dynamic<Info::T>: DynBind<E>, + Info: StructTypeInfo<'ctx, Mode, E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'a> Dynamic<&'a Info::T>: DynBind<E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, { fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E> where @@ -260,10 +284,17 @@ any_trait! { TagProto<tags::Map, E>, SequenceProto<E> ] where + for<'a> Dynamic<&'a Info::T>: DynBind<E>, E: Environment, Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, - for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, + Dynamic<Info::T>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<Info::T>: DynBind<E>, Mode: 'ctx, } @@ -271,7 +302,13 @@ impl<'ctx, Info, Mode: 'ctx, E> RequestHint<'ctx, E> for StructBuilder<'ctx, Inf where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, - for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, + Dynamic<Info::T>: DynBind<E>, + for<'a> Dynamic<&'a Info::T>: DynBind<E>, + for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, E: Environment, { #[inline(always)] @@ -338,18 +375,18 @@ where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, - for<'a> TypeName::T<'a, 'ctx, Info::ValueT, E>: DynBind<E>, + for<'a> Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>: DynBind<E>, { fn visit<'a>( &'a mut self, value: TypeName::T<'a, 'ctx, Info::ValueT, E>, - ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, Info::ValueT, E>>, E> + ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>>, E> where TypeName::T<'a, 'ctx, Info::ValueT, E>: Sized, 'ctx: 'a, { // Get the value from what we got from the walker. - self.inner = Inner::Value(Info::from_value(value)); + self.inner = Inner::Value(Dynamic(Info::from_value(value))); // Since we have the struct value we are done. E::value(Flow::Done.into()).cast() @@ -426,6 +463,9 @@ impl<'ctx, Info, Mode: 'ctx, E> Sequence<'ctx, E> for StructBuilder<'ctx, Info, where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, E: Environment, { fn visit<'a: 'c, 'b: 'c, 'c>( @@ -531,12 +571,18 @@ any_trait! { } where E: Environment, I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, } impl<'d, 'ctx, I, M, E> Tag<'ctx, tags::Key, E> for FieldVisitor<'d, 'ctx, I, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>, { fn visit<'a: 'c, 'b: 'c, 'c>( &'a mut self, @@ -574,17 +620,21 @@ any_trait! { ] where E: Environment, I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>, } impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<usize>, E> for NameVisitor<'ctx, I, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, { fn visit<'a>( &'a mut self, OwnedStatic(index): TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>, - ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>>, E> + ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>>>, E> where TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>: Sized, 'ctx: 'a, @@ -599,11 +649,12 @@ impl<'ctx, I, M, E> Value<'ctx, TempBorrowedStaticHrt<str>, E> for NameVisitor<' where E: Environment, I: StructTypeInfo<'ctx, M, E>, + for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>, { fn visit<'a>( &'a mut self, TempBorrowedStatic(name): TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>, - ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>, E> + ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>>, E> where TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, 'ctx: 'a, @@ -618,11 +669,12 @@ impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<&'static str>, E> for NameVisitor<'c where E: Environment, I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, { fn visit<'a>( &'a mut self, OwnedStatic(name): TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>, - ) -> NativeForm<'a, VisitResult<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>>, E> + ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>>>, E> where TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, 'ctx: 'a, |