Diffstat (limited to 'src/protocol/visitor/request_hint.rs')
-rw-r--r--src/protocol/visitor/request_hint.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/protocol/visitor/request_hint.rs b/src/protocol/visitor/request_hint.rs
index a110adb..5adcf8c 100644
--- a/src/protocol/visitor/request_hint.rs
+++ b/src/protocol/visitor/request_hint.rs
@@ -1,8 +1,7 @@
+use effectful::{closure::Capture, environment::{DynBind, Environment, NativeForm}};
+
use crate::{
any::TypeName,
- effect::{
- Effect, EffectExt as _, Effective as _, EffectiveExt as _, ErasedEffective, ReadyExt as _,
- },
hkt::Marker,
protocol::{DynVisitor, DynWalker},
};
@@ -10,32 +9,32 @@ use crate::{
use super::VisitResult;
/// Protocol for requesting a hint from a visitor.
-pub trait RequestHint<'ctx, E: Effect> {
+pub trait RequestHint<'ctx, E: Environment>: DynBind<E> {
/// Call this to request a hint.
///
/// `walker` is what the visitor (`self`) will call to give a hint using the
/// [`Hint`][crate::builtins::walker::Hint] protocol.
fn request_hint<'this: 'e, 'walker: 'e, 'e>(
&'this mut self,
- walker: DynWalker<'walker, 'ctx>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ walker: DynWalker<'walker, 'ctx, E>,
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'walker;
}
-pub struct RequestHintProto<E: Effect>(Marker<E>);
+pub struct RequestHintProto<E: Environment>(Marker<E>);
-impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for RequestHintProto<E>
+impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for RequestHintProto<E>
where
- E: Effect,
+ E: Environment,
{
- type T = dyn RequestHint<'ctx, E> + Send + Sync + 'a;
+ type T = dyn RequestHint<'ctx, E> + 'a;
}
-impl<'a, 'ctx, E> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()>
- for dyn RequestHint<'ctx, E> + Send + Sync + 'a
+impl<'a, 'ctx, E> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
+ for dyn RequestHint<'ctx, E> + 'a
where
- E: Effect,
+ E: Environment,
{
type Higher = RequestHintProto<E>;
}
@@ -47,11 +46,11 @@ where
/// If [`Flow::Done`] is returned then the visitor doesn't need any more information and the walker
/// should stop walking.
/// If [`Flow::Break`] is returned then there was an error and the walker should stop walking.
-pub fn request_hint<'ctx: 'visitor + 'walker, 'visitor: 'e, 'walker: 'e, 'e, E: Effect>(
- visitor: DynVisitor<'visitor, 'ctx>,
- walker: DynWalker<'walker, 'ctx>,
-) -> ErasedEffective<'e, VisitResult<DynWalker<'walker, 'ctx>>, E> {
- E::as_ctx((visitor, walker), |(visitor, walker)| {
+pub fn request_hint<'ctx: 'visitor + 'walker, 'visitor: 'e, 'walker: 'e, 'e, E: Environment>(
+ visitor: DynVisitor<'visitor, 'ctx, E>,
+ walker: DynWalker<'walker, 'ctx, E>,
+) -> NativeForm<'e, VisitResult<DynWalker<'walker, 'ctx, E>>, E> {
+ E::value(walker).update(Capture(visitor).fun_once(|visitor, walker, _| {
if let Some(object) = visitor.0.upcast_mut::<RequestHintProto<E>>() {
// Allow the visitor to give a hint if it wants.
object
@@ -60,8 +59,8 @@ pub fn request_hint<'ctx: 'visitor + 'walker, 'visitor: 'e, 'walker: 'e, 'e, E:
.cast()
} else {
// If the visitor doesn't support request hint then we continue.
- E::ready(VisitResult::Skipped(())).cast()
+ E::value(VisitResult::Skipped(())).cast()
}
- })
+ }))
.map(|((_, walker), result)| result.map_skipped(|_| walker))
}