Diffstat (limited to 'src/protocol/walker/hint.rs')
| -rw-r--r-- | src/protocol/walker/hint.rs | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs index c7d85d1..abdb136 100644 --- a/src/protocol/walker/hint.rs +++ b/src/protocol/walker/hint.rs @@ -7,7 +7,7 @@ use crate::{ any::{TypeName, TypeNameable}, nameable, - protocol::{ControlFlow, Visitor}, + protocol::{ControlFlowFor, Effect, SyncEffect, Visitor}, }; /// Meta information for the hint. @@ -17,38 +17,57 @@ pub trait HintMeta<'ctx> { /// Information known by the walker. /// /// This should be information easy to get without changing the state of the walker - /// in an irreversable way. + /// in an irreversible way. type Known<'a> where 'ctx: 'a; /// Extra information the visitor can give to the walker about what it is expecting. - type Hint; + type Hint<'a> + where + 'ctx: 'a; } /// Object implementing the [`Hint`] protocol. -pub trait Hint<'ctx, Protocol: HintMeta<'ctx>> { +pub trait Hint<'ctx, Protocol: HintMeta<'ctx>, E: Effect = SyncEffect> { /// Hint to the walker to use the `P` protocol. /// /// This should only be called once per [`RequestHint`]. - fn hint(&mut self, visitor: Visitor<'_, 'ctx>, hint: Protocol::Hint) -> ControlFlow; + fn hint<'a>( + &'a mut self, + visitor: &'a mut Visitor<'ctx>, + hint: Protocol::Hint<'a>, + ) -> ControlFlowFor<'a, E>; /// Ask the walker for information about it's support of the protocol. - fn known(&mut self, hint: &Protocol::Hint) -> ControlFlow<(), Protocol::Known<'_>>; + fn known<'a>( + &'a mut self, + hint: &'a Protocol::Hint<'a>, + ) -> ControlFlowFor<'a, E, Protocol::Known<'_>> + where + 'ctx: 'a; } nameable! { - pub struct Name['a, 'ctx, Protocol]; - impl [Protocol::Name] for dyn Hint<'ctx, Protocol> + 'a where { - Protocol: TypeNameable<'a, 'ctx> + ?Sized, 'ctx: 'a + pub struct Name['a, 'ctx, Protocol, E]; + + impl [Protocol::Name, E] for dyn Hint<'ctx, Protocol, E> + 'a where { + Protocol: TypeNameable<'a, 'ctx> + ?Sized, + E: Effect + 'static, + 'ctx: 'a, } - impl [Protocol] where dyn Hint<'ctx, Protocol::Nameable> + 'a { - Protocol: TypeName<'a, 'ctx> + ?Sized, 'ctx: 'a + + impl [Protocol, E] where dyn Hint<'ctx, Protocol::Nameable, E> + 'a { + Protocol: TypeName<'a, 'ctx> + ?Sized, + E: Effect + 'static, + 'ctx: 'a, } } #[cfg(test)] mod test { + use core::ops::ControlFlow; + use crate::any::{LtTypeId, TypeNameable}; use super::*; @@ -64,18 +83,21 @@ mod test { } impl<'ctx, X> Hint<'ctx, Y> for X { - fn hint( - &mut self, - visitor: Visitor<'_, 'ctx>, - hint: <Y as HintMeta<'_>>::Hint, + fn hint<'a>( + &'a mut self, + visitor: &'a mut Visitor<'ctx>, + hint: <Y as HintMeta<'ctx>>::Hint<'a>, ) -> ControlFlow<()> { todo!() } - fn known( - &mut self, - hint: &<Y as HintMeta<'_>>::Hint, - ) -> ControlFlow<(), <Y as HintMeta<'_>>::Known<'_>> { + fn known<'a>( + &'a mut self, + hint: &'a <Y as HintMeta<'ctx>>::Hint<'a>, + ) -> ControlFlow<(), <Y as HintMeta<'ctx>>::Known<'a>> + where + 'ctx: 'a, + { todo!() } } @@ -83,7 +105,7 @@ mod test { impl<'ctx> HintMeta<'ctx> for Y { type Known<'a> = () where 'ctx: 'a; - type Hint = (); + type Hint<'a> = () where 'ctx: 'a; } let x = X; |