Diffstat (limited to 'src/protocol/visitor/sequence.rs')
| -rw-r--r-- | src/protocol/visitor/sequence.rs | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/src/protocol/visitor/sequence.rs b/src/protocol/visitor/sequence.rs index db3e3cc..1fa221c 100644 --- a/src/protocol/visitor/sequence.rs +++ b/src/protocol/visitor/sequence.rs @@ -1,16 +1,14 @@ use effectful::{ effective::Effective, - environment::{DynBind, EnvConfig, Environment, NativeForm}, + environment::{DynBind, EnvConfig, Environment, InEnvironment, NativeForm}, + higher_ranked::Rank1, SendSync, }; use crate::{ - any::TypeName, + any::type_name, hkt::Marker, - protocol::{ - walker::hint::{HasProtocol, HintMeta, Meta}, - DynVisitor, - }, + protocol::{walker::hint::HintMeta, DynVisitor}, Flow, }; @@ -29,23 +27,33 @@ pub trait Sequence<'ctx, E: Environment>: DynBind<E> { 'ctx: 'a; } -#[derive(SendSync)] -pub struct SequenceProto<E: Environment>(Marker<E>); +const _: () = { + pub struct SequenceProto<E: Environment>(Marker<E>); -impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceProto<E> -where - E: Environment, -{ - type T = dyn Sequence<'ctx, E> + 'a; -} + impl<'a, 'ctx, E> type_name::Lower<'a, 'ctx, &'a &'ctx ()> for SequenceProto<E> + where + E: Environment, + { + type Lowered = dyn Sequence<'ctx, E> + 'a; + } -impl<'a, 'ctx, E> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for dyn Sequence<'ctx, E> + 'a -where - E: Environment, -{ - type Higher = SequenceProto<E>; -} + impl<'a, 'ctx, E> type_name::Raise<'a, 'ctx, &'a &'ctx ()> for dyn Sequence<'ctx, E> + 'a + where + E: Environment, + { + type Raised = SequenceProto<E>; + } + + impl<'a, 'ctx, E: Environment> HintMeta for SequenceProto<E> { + type Known = Rank1<SequenceKnown>; + + type Hint = Rank1<SequenceHint>; + } + + impl<'a, 'ctx, E: Environment> InEnvironment for SequenceProto<E> { + type Env = E; + } +}; pub trait SequenceScope<'ctx, E: Environment>: DynBind<E> { fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E>; @@ -65,41 +73,21 @@ pub struct SequenceKnown { pub len: (usize, Option<usize>), } -impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceKnown { - type T = SequenceKnown; -} - -impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for SequenceKnown { - type Higher = SequenceKnown; -} - #[derive(SendSync)] pub struct SequenceHint { pub len: (usize, Option<usize>), } -impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceHint { - type T = SequenceHint; -} - -impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for SequenceHint { - type Higher = SequenceHint; -} - -impl<E: Environment> HintMeta for SequenceProto<E> { - type Known = SequenceKnown; - - type Hint = SequenceHint; - - type Effect = E; -} - #[inline(always)] pub fn visit_sequence<'a, 'ctx, E: Environment>( visitor: DynVisitor<'a, 'ctx, E>, scope: DynSequenceScope<'a, 'ctx, E>, ) -> NativeForm<'a, VisitResult, E> { - if let Some(object) = visitor.0.upcast_mut::<SequenceProto<E>>() { + if let Some(object) = visitor + .0 + .cast_mut() + .upcast_mut::<dyn Sequence<'ctx, E> + 'a>() + { // Allow the visitor to walk the sequence scope. object.visit(scope) } else { @@ -107,5 +95,3 @@ pub fn visit_sequence<'a, 'ctx, E: Environment>( E::value(VisitResult::Skipped(())).cast() } } - -impl<'ctx, T, E: Environment> HasProtocol<SequenceProto<E>> for T where T: Sequence<'ctx, E> {} |