Diffstat (limited to 'src/protocol/walker/hint.rs')
-rw-r--r--src/protocol/walker/hint.rs111
1 files changed, 26 insertions, 85 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index 9bb35e6..9253264 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -9,12 +9,12 @@ use crate::{
effect::{Effect, Future},
higher_ranked_trait, higher_ranked_type,
hkt::Marker,
- protocol::Visitor,
+ protocol::DynVisitor,
Flow,
};
higher_ranked_trait! {
- pub type class HintKnown for<'a, 'ctx> {
+ pub type class Meta for<'a, 'ctx> {
type Bound = &'a &'ctx ();
type T: { Send + Sized } where { 'ctx: 'a };
@@ -23,6 +23,13 @@ higher_ranked_trait! {
}
}
+higher_ranked_type! {
+ impl Meta {
+ impl['a, 'ctx] type T['a, 'ctx] for () = ();
+ impl['a, 'ctx] type HigherRanked['a, 'ctx] for () = ();
+ }
+}
+
/// Meta information for the hint.
///
/// This gives the visitor more information to work from when selecting a hint.
@@ -31,115 +38,49 @@ pub trait HintMeta: Send + Sync + 'static {
///
/// This should be information easy to get without changing the state of the walker
/// in an irreversible way.
- type Known: HintKnown::MemberType;
+ type Known: Meta::MemberType;
/// Extra information the visitor can give to the walker about what it is expecting.
- type Hint;
+ type Hint: Meta::MemberType;
+
+ type Effect: Effect;
}
-pub type Known<'a, 'ctx, Protocol> = HintKnown::T<'a, 'ctx, <Protocol as HintMeta>::Known>;
+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>;
/// Object implementing the [`Hint`] protocol.
-pub trait Hint<'ctx, Protocol: ?Sized + HintMeta, E: Effect> {
+pub trait Hint<'ctx, Protocol: ?Sized + HintMeta> {
/// Hint to the walker to use the `P` protocol.
///
/// This should only be called once per [`RequestHint`].
fn hint<'a>(
&'a mut self,
- visitor: Visitor<'a, 'ctx>,
- hint: <Protocol as HintMeta>::Hint,
- ) -> Future<'a, Flow, E>;
+ visitor: DynVisitor<'a, 'ctx>,
+ hint: MetaHint<'a, 'ctx, Protocol>,
+ ) -> Future<'a, Flow, Protocol::Effect>;
/// Ask the walker for information about it's support of the protocol.
fn known<'a>(
&'a mut self,
- hint: &'a <Protocol as HintMeta>::Hint,
- ) -> Future<'a, Result<Known<'a, 'ctx, Protocol>, ()>, E>;
+ hint: &'a MetaHint<'a, 'ctx, Protocol>,
+ ) -> Future<'a, Result<MetaKnown<'a, 'ctx, Protocol>, ()>, Protocol::Effect>;
}
-pub struct HintProto<Protocol: ?Sized, E: Effect>(Marker<(*const Protocol, E)>);
+pub struct HintProto<Protocol: ?Sized>(Marker<Protocol>);
higher_ranked_type! {
impl TypeName {
- impl['a, 'ctx, Protocol, E] type T['a, 'ctx] for HintProto<Protocol, E> =
- dyn Hint<'ctx, Protocol, E> + Send + Sync + 'a
+ impl['a, 'ctx, Protocol] type T['a, 'ctx] for HintProto<Protocol> =
+ dyn Hint<'ctx, Protocol> + Send + Sync + 'a
where {
Protocol: 'static,
- E: Effect
};
- impl['a, 'ctx, Protocol, E] type HigherRanked['a, 'ctx] for dyn Hint<'ctx, Protocol, E> + Send + Sync + 'a =
- HintProto<Protocol, E>
+ impl['a, 'ctx, Protocol] type HigherRanked['a, 'ctx] for dyn Hint<'ctx, Protocol> + Send + Sync + 'a =
+ HintProto<Protocol>
where {
Protocol: 'static,
- E: Effect,
};
}
}
-
-// #[cfg(test)]
-// mod test {
-// use crate::{
-// effect::{BlockOn, Blocking, Spin},
-// };
-//
-// use super::*;
-//
-// #[test]
-// fn demo() {
-// struct X<'ctx>(&'ctx mut i32);
-//
-// #[derive(Debug)]
-// struct Y;
-//
-// bijective_higher_ranked_type! {
-// type DynY['ctx][]: WithContextLt['ctx][] for<'a> (Y)
-// }
-//
-// bijective_higher_ranked_type! {
-// type [][]: TypeName[][] for<'ctx> (DynY<'ctx>)
-// }
-//
-// impl<'ctx, E: Effect<'ctx>> Hint<'ctx, DynY<'ctx>, E> for X<'ctx> {
-// fn hint<'a>(
-// &'a mut self,
-// _visitor: Visitor<'a, 'ctx>,
-// _hint: <DynY<'ctx> as HintMeta<'ctx>>::Hint,
-// ) -> Future<'a, 'ctx, Flow, E> {
-// todo!()
-// }
-//
-// fn known<'a>(
-// &'a mut self,
-// _hint: &'a <DynY<'ctx> as HintMeta<'ctx>>::Hint,
-// ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynY<'ctx>>, ()>, E> {
-// E::ready(Ok(&mut *self.0))
-// }
-// }
-//
-// higher_ranked_type! {
-// type KnownHkt['ctx]: (AnySend) = for<'lt> &'lt mut i32
-// }
-//
-// impl<'ctx> HintMeta<'ctx> for DynY<'ctx> {
-// type Known = KnownHkt<'ctx>;
-//
-// type Hint = ();
-// }
-//
-// let mut z = 42;
-// let mut x = X(&mut z);
-// let y: &mut WithContextLt::T<'_, '_, DynHint<'_, DynY<'_>, Blocking>> = &mut x;
-//
-// fn id<'a, 'ctx, T: ?Sized + TypeName::LowerType<'ctx>>(_x: &WithContextLt::T<'a, 'ctx, T>) {
-// }
-// id::<DynHint<'_, DynY<'_>, Blocking>>(y);
-//
-// let x = Spin::block_on(y.known(&()));
-// match x {
-// Ok(value) => *value += 1,
-// Err(_) => todo!(),
-// }
-// assert_eq!(z, 43);
-// }
-// }