Diffstat (limited to 'src/protocol/walker/hint.rs')
-rw-r--r--src/protocol/walker/hint.rs83
1 files changed, 43 insertions, 40 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index 049d881..50cd71d 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -6,9 +6,10 @@
use core::ops::{Deref, DerefMut};
+use effectful::environment::{DynBind, EnvConfig, Environment, NativeForm};
+
use crate::{
any::{AnyTrait, TypeName},
- effect::{Effect, EffectiveExt as _, ErasedEffective, ReadyExt as _, Ss},
hkt::Marker,
protocol::{visitor::VisitResult, DynVisitor, DynWalker},
Flow,
@@ -16,59 +17,61 @@ use crate::{
#[allow(non_snake_case)]
pub mod Meta {
- pub trait MemberTypeForLt<'a, 'ctx: 'a, B> {
- type T: ?Sized + LowerTypeWithBound<'a, 'ctx, &'a &'ctx (), Higher = Self>;
+ use effectful::environment::{DynBind, EnvConfig};
+
+ pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B> {
+ type T: ?Sized + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx (), Higher = Self>;
}
- pub trait MemberType: for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> {}
+ pub trait MemberType<E: EnvConfig>: for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> {}
- impl<T: ?Sized> MemberType for T where T: for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> {}
+ impl<T: ?Sized, E: EnvConfig> MemberType<E> for T where T: for<'a, 'ctx> MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> {}
- pub trait LowerTypeWithBound<'a, 'ctx: 'a, B>: 'a + Send + Sync + Sized {
- type Higher: ?Sized + MemberTypeForLt<'a, 'ctx, &'a &'ctx (), T = Self> + MemberType;
+ pub trait LowerTypeWithBound<'a, 'ctx: 'a, E: EnvConfig, B>: 'a + DynBind<E> + Sized {
+ type Higher: ?Sized + MemberTypeForLt<'a, 'ctx, E, &'a &'ctx (), T = Self>;
}
- pub trait LowerType<'a, 'ctx: 'a>: LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> {}
+ pub trait LowerType<'a, 'ctx: 'a, E: EnvConfig>: LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> {}
- impl<'a, 'ctx: 'a, T: ?Sized> LowerType<'a, 'ctx> for T where
- T: LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()>
+ impl<'a, 'ctx: 'a, E: EnvConfig, T: ?Sized> LowerType<'a, 'ctx, E> for T where
+ T: LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>
{
}
- pub type T<'a, 'ctx, __> = <__ as MemberTypeForLt<'a, 'ctx, &'a &'ctx ()>>::T;
- pub type HigherRanked<'a, 'ctx, __> =
- <__ as LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()>>::Higher;
+ pub type T<'a, 'ctx, __, E> = <__ as MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>>::T;
+ pub type HigherRanked<'a, 'ctx, __, E> =
+ <__ as LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>>::Higher;
}
-impl<'a, 'ctx> Meta::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()> for () {
+impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for () {
type T = ();
}
-impl<'a, 'ctx: 'a> Meta::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()> for () {
+impl<'a, 'ctx: 'a, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> for () {
type Higher = ();
}
/// Meta information for the hint.
///
/// This gives the visitor more information to work from when selecting a hint.
-pub trait HintMeta: TypeName::MemberType + Send + Sync + 'static {
+pub trait HintMeta: TypeName::MemberType<Self::Effect> + 'static {
/// Information known by the walker.
///
/// This should be information easy to get without changing the state of the walker
/// in an irreversible way.
- type Known: Meta::MemberType;
+ type Known: Meta::MemberType<Self::Effect>;
/// Extra information the visitor can give to the walker about what it is expecting.
- type Hint: Meta::MemberType;
+ type Hint: Meta::MemberType<Self::Effect>;
- type Effect: Effect;
+ type Effect: Environment;
}
-pub type MetaKnown<'a, 'ctx, Protocol> = Meta::T<'a, 'ctx, <Protocol as HintMeta>::Known>;
-pub type MetaHint<'a, 'ctx, Protocol> = Meta::T<'a, 'ctx, <Protocol as HintMeta>::Hint>;
+pub type MetaKnown<'a, 'ctx, Protocol> = Meta::T<'a, 'ctx, <Protocol as HintMeta>::Known, <Protocol as HintMeta>::Effect>;
+pub type MetaHint<'a, 'ctx, Protocol> = Meta::T<'a, 'ctx, <Protocol as HintMeta>::Hint, <Protocol as HintMeta>::Effect>;
/// Object implementing the [`Hint`] protocol.
-pub trait Hint<'ctx, Protocol: ?Sized + HintMeta> {
+pub trait Hint<'ctx, Protocol: ?Sized + HintMeta>: DynBind<Protocol::Effect> {
/// Hint to the walker to use the `P` protocol.
///
/// This should only be called once per [`RequestHint`].
@@ -76,7 +79,7 @@ pub trait Hint<'ctx, Protocol: ?Sized + HintMeta> {
&'this mut self,
visitor: DynVisitorWith<'visitor, 'ctx, Protocol>,
hint: MetaHint<'hint, 'ctx, Protocol>,
- ) -> ErasedEffective<'e, VisitResult, Protocol::Effect>
+ ) -> NativeForm<'e, VisitResult, Protocol::Effect>
where
'ctx: 'this + 'visitor + 'hint + 'e;
@@ -84,11 +87,11 @@ pub trait Hint<'ctx, Protocol: ?Sized + HintMeta> {
fn known<'a>(
&'a mut self,
hint: &'a MetaHint<'a, 'ctx, Protocol>,
- ) -> ErasedEffective<'a, Result<MetaKnown<'a, 'ctx, Protocol>, ()>, Protocol::Effect>;
+ ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, Protocol>, ()>, Protocol::Effect>;
}
-pub struct DynVisitorWith<'temp, 'ctx, Protocol: ?Sized> {
- visitor: DynVisitor<'temp, 'ctx>,
+pub struct DynVisitorWith<'temp, 'ctx, Protocol: ?Sized + HintMeta> {
+ visitor: DynVisitor<'temp, 'ctx, Protocol::Effect>,
_marker: Marker<Protocol>,
}
@@ -97,7 +100,7 @@ pub trait HasProtocol<Protocol: ?Sized> {}
impl<'temp, 'ctx: 'temp, Protocol: ?Sized + HintMeta> DynVisitorWith<'temp, 'ctx, Protocol> {
pub fn new<T>(visitor: &'temp mut T) -> Self
where
- T: AnyTrait<'ctx> + HasProtocol<Protocol> + Ss,
+ T: AnyTrait<'ctx, Protocol::Effect> + HasProtocol<Protocol>,
{
Self {
visitor: DynVisitor(visitor),
@@ -105,24 +108,24 @@ impl<'temp, 'ctx: 'temp, Protocol: ?Sized + HintMeta> DynVisitorWith<'temp, 'ctx
}
}
- pub fn as_known(&mut self) -> &mut TypeName::T<'_, 'ctx, Protocol> {
+ pub fn as_known(&mut self) -> &mut TypeName::T<'_, 'ctx, Protocol, Protocol::Effect> {
self.visitor.upcast_mut::<Protocol>().unwrap()
}
- pub fn into_inner(self) -> DynVisitor<'temp, 'ctx> {
+ pub fn into_inner(self) -> DynVisitor<'temp, 'ctx, Protocol::Effect> {
self.visitor
}
}
-impl<'temp, 'ctx, Protocol: ?Sized> Deref for DynVisitorWith<'temp, 'ctx, Protocol> {
- type Target = DynVisitor<'temp, 'ctx>;
+impl<'temp, 'ctx, Protocol: ?Sized + HintMeta> Deref for DynVisitorWith<'temp, 'ctx, Protocol> {
+ type Target = DynVisitor<'temp, 'ctx, Protocol::Effect>;
fn deref(&self) -> &Self::Target {
&self.visitor
}
}
-impl<'temp, 'ctx, Protocol: ?Sized> DerefMut for DynVisitorWith<'temp, 'ctx, Protocol> {
+impl<'temp, 'ctx, Protocol: ?Sized + HintMeta> DerefMut for DynVisitorWith<'temp, 'ctx, Protocol> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.visitor
}
@@ -130,16 +133,16 @@ impl<'temp, 'ctx, Protocol: ?Sized> DerefMut for DynVisitorWith<'temp, 'ctx, Pro
pub struct HintProto<Protocol: ?Sized>(Marker<Protocol>);
-impl<'a, 'ctx, Protocol: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, &'a &'ctx ()>
+impl<'a, 'ctx, Protocol: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, Protocol::Effect, &'a &'ctx ()>
for HintProto<Protocol>
where
Protocol: HintMeta,
{
- type T = dyn Hint<'ctx, Protocol> + Send + Sync + 'a;
+ type T = dyn Hint<'ctx, Protocol> + 'a;
}
-impl<'a, 'ctx, Protocol: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, &'a &'ctx ()>
- for dyn Hint<'ctx, Protocol> + Send + Sync + 'a
+impl<'a, 'ctx, Protocol: ?Sized> TypeName::LowerTypeWithBound<'a, 'ctx, Protocol::Effect, &'a &'ctx ()>
+ for dyn Hint<'ctx, Protocol> + 'a
where
Protocol: HintMeta,
{
@@ -147,7 +150,7 @@ where
}
pub fn hint_protocol<
- 'ctx,
+ 'ctx: 'e,
'walker: 'e,
'visitor: 'e,
'hint: 'e,
@@ -155,12 +158,12 @@ pub fn hint_protocol<
Protocol: ?Sized + HintMeta,
T,
>(
- walker: DynWalker<'walker, 'ctx>,
+ walker: DynWalker<'walker, 'ctx, Protocol::Effect>,
visitor: &'visitor mut T,
hint: MetaHint<'hint, 'ctx, Protocol>,
-) -> ErasedEffective<'e, VisitResult<()>, Protocol::Effect>
+) -> NativeForm<'e, VisitResult<()>, Protocol::Effect>
where
- T: AnyTrait<'ctx> + HasProtocol<Protocol> + Ss,
+ T: AnyTrait<'ctx, Protocol::Effect> + HasProtocol<Protocol>,
{
if let Some(object) = walker.0.upcast_mut::<HintProto<Protocol>>() {
object