Diffstat (limited to 'src/protocol/walker/hint.rs')
| -rw-r--r-- | src/protocol/walker/hint.rs | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs index 52da09b..16b2515 100644 --- a/src/protocol/walker/hint.rs +++ b/src/protocol/walker/hint.rs @@ -12,6 +12,7 @@ use crate::{ hkt::AnySend, nameable, protocol::Visitor, + Flow, }; /// Meta information for the hint. @@ -31,35 +32,35 @@ pub trait HintMeta<'ctx> { 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>> { - type Effect: Effect<'ctx>; - +pub trait Hint<'a, 'ctx: 'a, Protocol: ?Sized + HintMeta<'ctx>, E: Effect<'ctx>> { /// Hint to the walker to use the `P` protocol. /// /// This should only be called once per [`RequestHint`]. - fn hint<'a>( + fn hint( &'a mut self, visitor: Visitor<'a, 'ctx>, hint: <Protocol as HintMeta<'ctx>>::Hint, - ) -> Future<'a, 'ctx, ControlFlow<(), ()>, Self::Effect>; + ) -> Future<'a, 'ctx, Flow, E>; /// Ask the walker for information about it's support of the protocol. - fn known<'a>( + fn known( &'a mut self, hint: &'a <Protocol as HintMeta<'ctx>>::Hint, - ) -> Future<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>, Self::Effect>; + ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Protocol>, ()>, E>; } +pub type DynHint<'a, 'ctx, Protocol, E> = dyn Hint<'a, 'ctx, Protocol, E> + Send + 'a; + nameable! { pub struct Name['a, 'ctx, Protocol, E]; - impl [Protocol::Name, E] for dyn Hint<'ctx, Protocol, Effect = E> + 'a where { + impl [Protocol::Name, E] for DynHint<'a, 'ctx, Protocol, E> where { Protocol: TypeNameable<'a, 'ctx> + ?Sized, E: Effect<'ctx>, 'ctx: 'a, } - impl [Protocol, E] where dyn Hint<'ctx, Protocol::Nameable, Effect = E> + 'a { + impl [Protocol, E] where DynHint<'a, 'ctx, Protocol::Nameable, E> { Protocol: TypeName<'a, 'ctx> + ?Sized, E: Effect<'ctx>, 'ctx: 'a, @@ -90,22 +91,20 @@ mod test { impl for Y where {} } - impl<'ctx> Hint<'ctx, Y> for X<'ctx> { - type Effect = Blocking; - - fn hint<'a>( + impl<'a, 'ctx: 'a, E: Effect<'ctx>> Hint<'a, 'ctx, Y, E> for X<'ctx> { + fn hint( &'a mut self, _visitor: Visitor<'a, 'ctx>, _hint: <Y as HintMeta<'ctx>>::Hint, - ) -> Future<'a, 'ctx, ControlFlow<(), ()>, Self::Effect> { + ) -> Future<'a, 'ctx, Flow, E> { todo!() } - fn known<'a>( + fn known( &'a mut self, _hint: &'a <Y as HintMeta<'ctx>>::Hint, - ) -> Future<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Y>>, Self::Effect> { - Self::Effect::wrap(async { ControlFlow::Continue(&mut *self.0) }) + ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Y>, ()>, E> { + E::ready(Ok(&mut *self.0)) } } @@ -121,15 +120,15 @@ mod test { let mut z = 42; let mut x = X(&mut z); - let y: &mut dyn Hint<'_, Y, Effect = Blocking> = &mut x; + let y: &mut DynHint<'_, '_, 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!(), + Ok(value) => *value += 1, + Err(_) => todo!(), } assert_eq!(z, 43); } |