Diffstat (limited to 'src/protocol/walker/hint.rs')
-rw-r--r--src/protocol/walker/hint.rs75
1 files changed, 43 insertions, 32 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index 46ad675..2d723e4 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -8,7 +8,8 @@ use core::ops::ControlFlow;
use crate::{
any::{TypeName, TypeNameable},
- effect::{any_t, Effect, EffectAnyTrait, SyncEffect, Yield},
+ effect::{Effect, Future},
+ hkt::AnySend,
nameable,
protocol::Visitor,
};
@@ -21,36 +22,34 @@ pub trait HintMeta<'ctx> {
///
/// This should be information easy to get without changing the state of the walker
/// in an irreversible way.
- type Known: any_t::Hkt<'ctx>;
+ type Known: AnySend::Trait<'ctx>;
/// Extra information the visitor can give to the walker about what it is expecting.
type Hint;
}
-pub type Known<'a, 'ctx, Protocol> = any_t::T<'a, 'ctx, <Protocol as HintMeta<'ctx>>::Known>;
+pub type Known<'a, 'ctx, Protocol> = AnySend::T<'a, 'ctx, <Protocol as HintMeta<'ctx>>::Known>;
/// Object implementing the [`Hint`] protocol.
pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E>
where
- for<'a> E: Effect<'ctx, ControlFlow<(), ()>>
- + Effect<'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>>,
+ E: Effect<'ctx>,
+ E: for<'a> Effect<'ctx>,
{
/// 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, E>,
+ visitor: Visitor<'a, 'ctx>,
hint: <Protocol as HintMeta<'ctx>>::Hint,
- ) -> Yield<'a, 'ctx, ControlFlow<(), ()>, E>;
+ ) -> Future<'a, 'ctx, ControlFlow<(), ()>, E>;
/// Ask the walker for information about it's support of the protocol.
fn known<'a>(
&'a mut self,
hint: &'a <Protocol as HintMeta<'ctx>>::Hint,
- ) -> Yield<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>, E>
- where
- 'ctx: 'a;
+ ) -> Future<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>, E>;
}
nameable! {
@@ -58,13 +57,13 @@ nameable! {
impl [Protocol::Name, E] for dyn Hint<'ctx, Protocol, E> + 'a where {
Protocol: TypeNameable<'a, 'ctx> + ?Sized,
- E: Effect<'ctx, ControlFlow<(), ()>>,
+ E: Effect<'ctx>,
'ctx: 'a,
}
impl [Protocol, E] where dyn Hint<'ctx, Protocol::Nameable, E> + 'a {
Protocol: TypeName<'a, 'ctx> + ?Sized,
- E: Effect<'ctx, ControlFlow<(), ()>>,
+ E: Effect<'ctx>,
'ctx: 'a,
}
}
@@ -73,14 +72,19 @@ nameable! {
mod test {
use core::ops::ControlFlow;
- use crate::any::{LtTypeId, TypeNameable};
- use crate::hkt::hkt;
+ use crate::{
+ any::TypeNameable,
+ effect::{BlockOn, Blocking, Spin},
+ higher_ranked_type,
+ };
use super::*;
#[test]
fn demo() {
- struct X;
+ struct X<'ctx>(&'ctx mut i32);
+
+ #[derive(Debug)]
struct Y;
nameable! {
@@ -88,27 +92,29 @@ mod test {
impl for Y where {}
}
- impl<'ctx, X> Hint<'ctx, Y> for X {
+ impl<'ctx, E> Hint<'ctx, Y, E> for X<'ctx>
+ where
+ E: Effect<'ctx>,
+ {
fn hint<'a>(
&'a mut self,
- visitor: Visitor<'a, 'ctx, SyncEffect>,
- hint: <Y as HintMeta<'ctx>>::Hint,
- ) -> ControlFlow<()> {
+ _visitor: Visitor<'a, 'ctx>,
+ _hint: <Y as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, ControlFlow<(), ()>, E> {
todo!()
}
fn known<'a>(
&'a mut self,
- hint: &'a <Y as HintMeta<'ctx>>::Hint,
- ) -> ControlFlow<(), Known<'a, 'ctx, SyncEffect>>
- where
- 'ctx: 'a,
- {
- todo!()
+ _hint: &'a <Y as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Y>>, E> {
+ E::wrap(async { ControlFlow::Continue(&mut *self.0) })
}
}
- hkt!((any_t): for<'a, 'ctx> KnownHkt => ());
+ higher_ranked_type! {
+ type KnownHkt['ctx]: (AnySend) = for<'lt> &'lt mut i32
+ }
impl<'ctx> HintMeta<'ctx> for Y {
type Known = KnownHkt<'ctx>;
@@ -116,13 +122,18 @@ mod test {
type Hint = ();
}
- let x = X;
- let y: &dyn Hint<'_, Y> = &x;
-
- fn id<'a, 'ctx, T: ?Sized + TypeNameable<'a, 'ctx>>(x: &T) {
- dbg!(LtTypeId::of::<T>());
- }
+ let mut z = 42;
+ let mut x = X(&mut z);
+ let y: &mut dyn Hint<'_, Y, Blocking> = &mut x;
+ fn id<'a, 'ctx, T: ?Sized + TypeNameable<'a, 'ctx>>(_x: &T) {}
id(y);
+
+ let x = Spin::block_on(y.known(&()));
+ match x {
+ ControlFlow::Continue(value) => *value += 1,
+ ControlFlow::Break(_) => todo!(),
+ }
+ assert_eq!(z, 43);
}
}