Diffstat (limited to 'src/build/builders/core/struct.rs')
| -rw-r--r-- | src/build/builders/core/struct.rs | 290 |
1 files changed, 171 insertions, 119 deletions
diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs index 555314d..24172b3 100644 --- a/src/build/builders/core/struct.rs +++ b/src/build/builders/core/struct.rs @@ -1,27 +1,26 @@ use core::fmt::{Debug, Display}; use effectful::{ - bound::{Dynamic, IsSend, IsSync}, + bound::Dynamic, effective::Effective, environment::{DynBind, Environment, NativeForm}, - higher_ranked::Mut, tri, SendSync, }; use crate::{ - any::{OwnedStatic, TempBorrowedStatic, TempBorrowedStaticHrt, TypeName}, - any_trait, + any::{type_name, AnyTrait, OwnedStatic, TempBorrowedStatic}, + build::BuilderTypes, hkt::Marker, protocol::{ visitor::{ - tags, DynSequenceScope, EffectiveVisitExt as _, RequestHint, RequestHintProto, - Sequence, SequenceHint, SequenceProto, Tag, TagConst, TagHint, TagProto, Value, - ValueProto, VisitResult, + tags, DynSequenceScope, EffectiveVisitExt as _, RequestHint, Sequence, SequenceHint, + Tag, TagConst, TagHint, Value, VisitResult, }, walker::hint::hint_protocol, AsVisitor, DynVisitor, DynWalker, }, - Builder, BuilderTypes, DynWalkerObjSafe, Flow, + walk::DynWalkerObjSafe, + Builder, Flow, }; use super::NoopVisitor; @@ -85,7 +84,7 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static { type Error: DynBind<E> + Debug + Display; /// The kind of type for enabling the direct value protocol. - type ValueT: TypeName::MemberType<E>; + type ValueT: type_name::Static; /// The struct type this info is for. type T; @@ -119,7 +118,7 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static { fn marker_from_name(name: &str) -> Option<Self::FieldMarker>; /// Get the value from the value protocol. - fn from_value<'a>(value: TypeName::T<'a, 'ctx, Self::ValueT, E>) -> Self::T; + fn from_value<'a>(value: type_name::Lowered<'a, 'ctx, Self::ValueT>) -> Self::T; } /// Error that [`StructBuilder`] returns. @@ -213,9 +212,9 @@ where Dynamic<OwnedStatic<usize>>: DynBind<E>, Dynamic<OwnedStatic<String>>: 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<type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, Dynamic<OwnedStatic<&'static str>>: DynBind<E>, - for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, { fn from_seed<'a>(seed: Self::Seed) -> NativeForm<'a, Self, E> @@ -264,9 +263,9 @@ where for<'a> Dynamic<&'a Info::T>: DynBind<E>, Dynamic<OwnedStatic<usize>>: DynBind<E>, Dynamic<OwnedStatic<String>>: DynBind<E>, - for<'b, 'c> Dynamic<TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b, 'c> Dynamic<type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, - for<'b, 'c> Dynamic<&'b TypeName::T<'b, 'c, Info::ValueT, E>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, { fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E> where @@ -276,37 +275,55 @@ where } } -any_trait! { - impl['ctx, Info, Mode][E] StructBuilder<'ctx, Info, Mode, E> = [ - RequestHintProto<E>, - ValueProto<Info::ValueT, E>, - TagProto<tags::Struct, E>, - 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>, - Dynamic<Info::T>: DynBind<E>, - Dynamic<OwnedStatic<&'static str>>: DynBind<E>, - Dynamic<OwnedStatic<String>>: 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, +impl<'ctx, Info, Mode, E: Environment> AnyTrait<'ctx> for StructBuilder<'ctx, Info, Mode, E> +where + for<'a> Dynamic<&'a Info::T>: DynBind<E>, + E: Environment, + Self: DynBind<E>, + Info: StructTypeInfo<'ctx, Mode, E>, + Dynamic<Info::T>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + Dynamic<OwnedStatic<String>>: DynBind<E>, + for<'b, 'c> Dynamic<type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<Info::T>: DynBind<E>, + Mode: 'ctx, +{ } +// any_trait! { +// impl['ctx, Info, Mode][E] StructBuilder<'ctx, Info, Mode, E> = [ +// RequestHintProto<E>, +// ValueProto<Info::ValueT, E>, +// TagProto<tags::Struct, E>, +// 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>, +// Dynamic<Info::T>: DynBind<E>, +// Dynamic<OwnedStatic<&'static str>>: DynBind<E>, +// Dynamic<OwnedStatic<String>>: 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, +// } + impl<'ctx, Info, Mode: 'ctx, E> RequestHint<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, 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>, + for<'b, 'c> Dynamic<type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, + for<'b, 'c> Dynamic<&'b type_name::Lowered<'b, 'c, Info::ValueT>>: DynBind<E>, Dynamic<OwnedStatic<usize>>: DynBind<E>, for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, Dynamic<OwnedStatic<&'static str>>: DynBind<E>, @@ -325,13 +342,14 @@ where .update((), |_, (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::<dyn Value<'_, Info::ValueT, E>, _, _>(walker.cast(), *this, ()) + .cast() }) .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::<dyn Tag<'_, tags::Struct, E>, _, _>( walker.cast(), *this, TagHint { kind: TagConst }, @@ -343,7 +361,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::<dyn Tag<'_, tags::Map, E>, _, _>( walker.cast(), *this, TagHint { kind: TagConst }, @@ -354,7 +372,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::<dyn Sequence<'_, E>, _, _>( walker.cast(), *this, SequenceHint { @@ -377,15 +395,15 @@ where Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, - 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<Dynamic<TypeName::T<'a, 'ctx, Info::ValueT, E>>>, E> + fn visit<'this: 'value, 'value: 'e, 'e>( + &'this mut self, + value: type_name::Lowered<'value, 'ctx, Info::ValueT>, + ) -> NativeForm<'e, VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, Info::ValueT>>>, E> where - TypeName::T<'a, 'ctx, Info::ValueT, E>: Sized, - 'ctx: 'a, + type_name::Lowered<'value, 'ctx, Info::ValueT>: Sized, + Dynamic<type_name::Lowered<'value, 'ctx, Info::ValueT>>: DynBind<E>, + 'ctx: 'this + 'value, { // Get the value from what we got from the walker. self.inner = Inner::Value(Dynamic(Info::from_value(value))); @@ -558,28 +576,40 @@ struct FieldVisitor<'a, 'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> _marker: Marker<E>, } -any_trait! { - impl['ctx, 'a, I, M][E] FieldVisitor<'a, 'ctx, I, M, E> = [ - TagProto<tags::Key, E>, - ] ref { - let (_this, _id); - } else ref { - None - } mut { - let (this, id); - } else mut { - this.marker.and_then(|marker| { - I::as_visitor(marker, this.builders).0.upcast_to_id_mut(id) - }) - } where - E: Environment, - I: StructTypeInfo<'ctx, M, E>, - Dynamic<OwnedStatic<usize>>: DynBind<E>, - Dynamic<OwnedStatic<&'static str>>: DynBind<E>, - Dynamic<OwnedStatic<String>>: DynBind<E>, - for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, +impl<'a, 'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> AnyTrait<'ctx> + for FieldVisitor<'a, 'ctx, I, M, E> +where + E: Environment, + I: StructTypeInfo<'ctx, M, E>, + Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + Dynamic<OwnedStatic<String>>: DynBind<E>, + for<'b> Dynamic<TempBorrowedStatic<'b, str>>: DynBind<E>, +{ } +// any_trait! { +// impl['ctx, 'a, I, M][E] FieldVisitor<'a, 'ctx, I, M, E> = [ +// TagProto<tags::Key, E>, +// ] ref { +// let (_this, _id); +// } else ref { +// None +// } mut { +// let (this, id); +// } else mut { +// this.marker.and_then(|marker| { +// I::as_visitor(marker, this.builders).0.upcast_to_id_mut(id) +// }) +// } where +// E: Environment, +// I: StructTypeInfo<'ctx, M, E>, +// Dynamic<OwnedStatic<usize>>: DynBind<E>, +// Dynamic<OwnedStatic<&'static str>>: DynBind<E>, +// Dynamic<OwnedStatic<String>>: 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, @@ -617,76 +647,93 @@ struct NameVisitor<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> { _marker: Marker<E>, } -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>, - ValueProto<OwnedStatic<String>, E>, - ] where - E: Environment, - I: StructTypeInfo<'ctx, M, E>, - Dynamic<OwnedStatic<usize>>: DynBind<E>, - Dynamic<OwnedStatic<&'static str>>: DynBind<E>, - Dynamic<OwnedStatic<String>>: 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> +impl<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> AnyTrait<'ctx> + for NameVisitor<'ctx, I, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E>, Dynamic<OwnedStatic<usize>>: DynBind<E>, + Dynamic<OwnedStatic<&'static str>>: DynBind<E>, + Dynamic<OwnedStatic<String>>: DynBind<E>, + for<'a> Dynamic<TempBorrowedStatic<'a, str>>: DynBind<E>, { - fn visit<'a>( - &'a mut self, - OwnedStatic(index): TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>, - ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>>>, E> - where - TypeName::T<'a, 'ctx, OwnedStatic<usize>, E>: Sized, - 'ctx: 'a, - { - self.field_marker = I::marker_from_index(index); - - E::value(VisitResult::Control(Flow::Done)).cast() - } } -impl<'ctx, I, M, E> Value<'ctx, TempBorrowedStaticHrt<str>, E> for NameVisitor<'ctx, I, M, E> +// 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>, +// ValueProto<OwnedStatic<String>, E>, +// ] where +// E: Environment, +// I: StructTypeInfo<'ctx, M, E>, +// Dynamic<OwnedStatic<usize>>: DynBind<E>, +// Dynamic<OwnedStatic<&'static str>>: DynBind<E>, +// Dynamic<OwnedStatic<String>>: 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>, - 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<Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>>, E> + fn visit<'this: 'value, 'value: 'e, 'e>( + &'this mut self, + value: type_name::Lowered<'value, 'ctx, OwnedStatic<usize>>, + ) -> NativeForm<'e, VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<usize>>>>, E> where - TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, - 'ctx: 'a, + type_name::Lowered<'value, 'ctx, OwnedStatic<usize>>: Sized, + Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<usize>>>: DynBind<E>, + 'ctx: 'this + 'value, { - self.field_marker = I::marker_from_name(name); + self.field_marker = I::marker_from_index(value.0); E::value(VisitResult::Control(Flow::Done)).cast() } } +// impl<'ctx, I, M, E> Value<'ctx, TempBorrowedStatic<str>, E> for NameVisitor<'ctx, I, M, E> +// 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<Dynamic<TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>>>, E> +// where +// TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, +// 'ctx: 'a, +// { +// self.field_marker = I::marker_from_name(name); +// +// E::value(VisitResult::Control(Flow::Done)).cast() +// } +// } + impl<'ctx, I, M, E> Value<'ctx, OwnedStatic<&'static str>, E> for NameVisitor<'ctx, I, M, E> 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<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<&'static str>, E>>>, E> + fn visit<'this: 'value, 'value: 'e, 'e>( + &'this mut self, + value: type_name::Lowered<'value, 'ctx, OwnedStatic<&'static str>>, + ) -> NativeForm< + 'e, + VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<&'static str>>>>, + E, + > where - TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, - 'ctx: 'a, + type_name::Lowered<'value, 'ctx, OwnedStatic<&'static str>>: Sized, + Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<&'static str>>>: DynBind<E>, + 'ctx: 'this + 'value, { - self.field_marker = I::marker_from_name(name); + self.field_marker = I::marker_from_name(value.0); E::value(VisitResult::Control(Flow::Done)).cast() } @@ -698,15 +745,20 @@ where I: StructTypeInfo<'ctx, M, E>, Dynamic<OwnedStatic<String>>: DynBind<E>, { - fn visit<'a>( - &'a mut self, - OwnedStatic(name): TypeName::T<'a, 'ctx, OwnedStatic<String>, E>, - ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, OwnedStatic<String>, E>>>, E> + fn visit<'this: 'value, 'value: 'e, 'e>( + &'this mut self, + value: type_name::Lowered<'value, 'ctx, OwnedStatic<String>>, + ) -> NativeForm< + 'e, + VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<String>>>>, + E, + > where - TypeName::T<'a, 'ctx, TempBorrowedStaticHrt<str>, E>: Sized, - 'ctx: 'a, + type_name::Lowered<'value, 'ctx, OwnedStatic<String>>: Sized, + Dynamic<type_name::Lowered<'value, 'ctx, OwnedStatic<String>>>: DynBind<E>, + 'ctx: 'this + 'value, { - self.field_marker = I::marker_from_name(&name); + self.field_marker = I::marker_from_name(&value.0); E::value(VisitResult::Control(Flow::Done)).cast() } |