Diffstat (limited to 'src/protocol/walker/hint.rs')
| -rw-r--r-- | src/protocol/walker/hint.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs index ce73b7e..56d5793 100644 --- a/src/protocol/walker/hint.rs +++ b/src/protocol/walker/hint.rs @@ -4,10 +4,12 @@ //! this module gives a protocol by which a visitor can give a hint //! to the walker about what it is expecting. +use core::ops::ControlFlow; + use crate::{ any::{TypeName, TypeNameable}, nameable, - protocol::{ControlFlowFor, Effect, SyncEffect, Visitor, any_t}, + protocol::{any_t, Effect, EffectAnyTrait, SyncEffect, Visitor, Yield}, }; /// Meta information for the hint. @@ -18,16 +20,19 @@ pub trait HintMeta<'ctx> { /// /// This should be information easy to get without changing the state of the walker /// in an irreversible way. - type KnownHkt: any_t::Hkt<'ctx>; + type Known: any_t::Hkt<'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>; + /// Object implementing the [`Hint`] protocol. -pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E = SyncEffect> +pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E> where - E: Effect<'ctx> + for<'a> Effect<'ctx, <<Protocol as HintMeta<'ctx>>::KnownHkt as any_t::ForLt<'a, 'ctx, crate::hkt::Bound<'a, 'ctx>>>::T> + for<'a> E: Effect<'ctx, ControlFlow<(), ()>> + + Effect<'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>>, { /// Hint to the walker to use the `P` protocol. /// @@ -36,13 +41,13 @@ where &'a mut self, visitor: Visitor<'a, 'ctx, E>, hint: <Protocol as HintMeta<'ctx>>::Hint, - ) -> ControlFlowFor<'a, 'ctx, E>; + ) -> Yield<'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, - ) -> ControlFlowFor<'a, 'ctx, E, any_t::T<'a, 'ctx, <Protocol as HintMeta<'ctx>>::KnownHkt>> + ) -> Yield<'a, 'ctx, ControlFlow<(), Known<'a, 'ctx, Protocol>>, E> where 'ctx: 'a; } @@ -52,13 +57,13 @@ nameable! { impl [Protocol::Name, E] for dyn Hint<'ctx, Protocol, E> + 'a where { Protocol: TypeNameable<'a, 'ctx> + ?Sized, - E: Effect<'ctx>, + E: Effect<'ctx, ControlFlow<(), ()>>, 'ctx: 'a, } impl [Protocol, E] where dyn Hint<'ctx, Protocol::Nameable, E> + 'a { Protocol: TypeName<'a, 'ctx> + ?Sized, - E: Effect<'ctx>, + E: Effect<'ctx, ControlFlow<(), ()>>, 'ctx: 'a, } } @@ -94,7 +99,7 @@ mod test { fn known<'a>( &'a mut self, hint: &'a <Y as HintMeta<'ctx>>::Hint, - ) -> ControlFlow<(), any_t::T<'a, 'ctx, <Y as HintMeta<'ctx>>::KnownHkt>> + ) -> ControlFlow<(), Known<'a, 'ctx, SyncEffect>> where 'ctx: 'a, { @@ -105,7 +110,7 @@ mod test { hkt!((any_t): for<'a, 'ctx> KnownHkt => ()); impl<'ctx> HintMeta<'ctx> for Y { - type KnownHkt = KnownHkt<'ctx>; + type Known = KnownHkt<'ctx>; type Hint = (); } |