Diffstat (limited to 'src/protocol/visitor/sequence.rs')
-rw-r--r--src/protocol/visitor/sequence.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/protocol/visitor/sequence.rs b/src/protocol/visitor/sequence.rs
index f261eca..971532b 100644
--- a/src/protocol/visitor/sequence.rs
+++ b/src/protocol/visitor/sequence.rs
@@ -1,6 +1,7 @@
+use effectful::{environment::{DynBind, EnvConfig, Environment, NativeForm}, is_send_sync};
+
use crate::{
any::TypeName,
- effect::{Effect, ErasedEffective, ReadyExt as _},
hkt::Marker,
protocol::{
walker::hint::{HasProtocol, HintMeta, Meta},
@@ -15,55 +16,57 @@ use super::VisitResult;
///
/// This protocol uses a scope to give temporary control to the visitor.
/// The visitor will drive the walker for each item.
-pub trait Sequence<'ctx, E: Effect> {
+pub trait Sequence<'ctx, E: Environment>: DynBind<E> {
fn visit<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
scope: DynSequenceScope<'b, 'ctx, E>,
- ) -> ErasedEffective<'c, VisitResult, E>
+ ) -> NativeForm<'c, VisitResult, E>
where
'ctx: 'a;
}
-pub struct SequenceProto<E: Effect>(Marker<E>);
+pub struct SequenceProto<E: Environment>(Marker<E>);
-impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for SequenceProto<E>
+impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceProto<E>
where
- E: Effect,
+ E: Environment,
{
- type T = dyn Sequence<'ctx, E> + Send + Sync + 'a;
+ type T = dyn Sequence<'ctx, E> + 'a;
}
-impl<'a, 'ctx, E> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()>
- for dyn Sequence<'ctx, E> + Send + Sync + 'a
+impl<'a, 'ctx, E> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
+ for dyn Sequence<'ctx, E> + 'a
where
- E: Effect,
+ E: Environment,
{
type Higher = SequenceProto<E>;
}
-pub trait SequenceScope<'ctx, E: Effect> {
- fn size_hint(&mut self) -> ErasedEffective<'_, (usize, Option<usize>), E>;
+pub trait SequenceScope<'ctx, E: Environment>: DynBind<E> {
+ fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E>;
fn next<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
- visitor: DynVisitor<'b, 'ctx>,
- ) -> ErasedEffective<'c, Flow, E>
+ visitor: DynVisitor<'b, 'ctx, E>,
+ ) -> NativeForm<'c, Flow, E>
where
'ctx: 'c + 'a + 'b;
}
-pub type DynSequenceScope<'a, 'ctx, E> = &'a mut (dyn SequenceScope<'ctx, E> + Send + Sync + 'a);
+pub type DynSequenceScope<'a, 'ctx, E> = &'a mut (dyn SequenceScope<'ctx, E> + 'a);
#[derive(Default)]
pub struct SequenceKnown {
pub len: (usize, Option<usize>),
}
-impl<'a, 'ctx> Meta::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for SequenceKnown {
+is_send_sync!(SequenceKnown, SequenceHint);
+
+impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceKnown {
type T = SequenceKnown;
}
-impl<'a, 'ctx> Meta::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> for SequenceKnown {
+impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for SequenceKnown {
type Higher = SequenceKnown;
}
@@ -71,15 +74,15 @@ pub struct SequenceHint {
pub len: (usize, Option<usize>),
}
-impl<'a, 'ctx> Meta::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for SequenceHint {
+impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceHint {
type T = SequenceHint;
}
-impl<'a, 'ctx> Meta::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> for SequenceHint {
+impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for SequenceHint {
type Higher = SequenceHint;
}
-impl<E: Effect> HintMeta for SequenceProto<E> {
+impl<E: Environment> HintMeta for SequenceProto<E> {
type Known = SequenceKnown;
type Hint = SequenceHint;
@@ -88,17 +91,17 @@ impl<E: Effect> HintMeta for SequenceProto<E> {
}
#[inline(always)]
-pub fn visit_sequence<'a, 'ctx, E: Effect>(
- visitor: DynVisitor<'a, 'ctx>,
+pub fn visit_sequence<'a, 'ctx, E: Environment>(
+ visitor: DynVisitor<'a, 'ctx, E>,
scope: DynSequenceScope<'a, 'ctx, E>,
-) -> ErasedEffective<'a, VisitResult, E> {
+) -> NativeForm<'a, VisitResult, E> {
if let Some(object) = visitor.0.upcast_mut::<SequenceProto<E>>() {
// Allow the visitor to walk the sequence scope.
object.visit(scope)
} else {
// If the visitor doesn't support sequence then we continue.
- VisitResult::Skipped(()).ready()
+ E::value(VisitResult::Skipped(()))
}
}
-impl<'ctx, T, E: Effect> HasProtocol<SequenceProto<E>> for T where T: Sequence<'ctx, E> {}
+impl<'ctx, T, E: Environment> HasProtocol<SequenceProto<E>> for T where T: Sequence<'ctx, E> {}