Diffstat (limited to 'src/builtins/walker/hint.rs')
| -rw-r--r-- | src/builtins/walker/hint.rs | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/src/builtins/walker/hint.rs b/src/builtins/walker/hint.rs index 4392f73..a386f24 100644 --- a/src/builtins/walker/hint.rs +++ b/src/builtins/walker/hint.rs @@ -4,18 +4,16 @@ //! this module gives a protocol by which a visitor can give a hint //! to the walker about what it is expecting. -use core::marker::PhantomData; +use core::{marker::PhantomData}; use crate::{ - any::{TypeName, TypeNameable}, - nameable, - protocol::Implementer, + nameable, any::AnyTrait, builtins::{Visitor, ControlFlow}, }; /// Meta information for the hint. /// /// This gives the visitor more information to work from when selecting a hint. -pub trait Meta<'ctx> { +pub trait HintMeta<'ctx> { /// Information known by the walker. /// /// This should be information easy to get without changing the state of the walker @@ -27,44 +25,25 @@ pub trait Meta<'ctx> { } /// Object implementing the [`Hint`] protocol. -pub trait Hint<'ctx, P: Meta<'ctx>> { +pub trait Hint<'ctx, Protocol: HintMeta<'ctx>> { /// Hint to the walker to use the `P` protocol. /// /// This should only be called once per [`RequestHint`]. - fn hint(&mut self, visitor: &mut dyn Implementer<'ctx>, hint: P::Hint<'_>) -> Result<(), ()>; + fn hint(&mut self, visitor: Visitor<'_, 'ctx>, hint: Protocol::Hint<'_>) -> ControlFlow; /// Ask the walker for information about it's support of the protocol. - fn known(&mut self, hint: &P::Hint<'_>) -> Result<P::Known<'_>, ()>; + fn known(&mut self, hint: &Protocol::Hint<'_>) -> ControlFlow<(), Protocol::Known<'_>>; } -// nameable!(['a, 'ctx, P: Meta<'ctx> + TypeNameable<'a, 'ctx>]: dyn Hint<'ctx, P> + 'a => dyn Hint<'static, P::Name>); - -const _: () = { - impl<'a, 'ctx: 'a, P: TypeNameable<'a, 'ctx>> - crate::any::TypeNameable<'a, 'ctx> for dyn Hint<'ctx, P> + 'a - where - P: ?Sized - // where - // P: Meta<'ctx> - { - type Name = Name<P::Name>; - } - - pub struct Name<T: ?Sized>(PhantomData<fn() -> *const T>); - - impl<'a, 'ctx: 'a, T: TypeName<'a, 'ctx>> crate::any::TypeName<'a, 'ctx> for Name<T> - where - T: ?Sized - // where - // T::Nameable: Meta<'ctx>, - { - type Nameable = dyn Hint<'ctx, T::Nameable> + 'a; - } -}; +nameable! { + pub ['a, 'ctx, Protocol] + dyn Hint<'ctx, Protocol> + 'a where {'ctx: 'a, Protocol: ?Sized} + dyn Hint<'ctx, Protocol::Nameable> + 'a where {'ctx: 'a, Protocol: ?Sized} +} #[cfg(test)] mod test { - use crate::any::LtTypeId; + use crate::any::{LtTypeId, TypeNameable}; use super::*; @@ -73,26 +52,29 @@ mod test { struct X; struct Y; - nameable!(['a, 'ctx]: Y => Y); + nameable! { + ['a, 'ctx] + Y where {} + } impl<'ctx, X> Hint<'ctx, Y> for X { fn hint( &mut self, - visitor: &mut dyn Implementer<'ctx>, - hint: <Y as Meta>::Hint<'_>, - ) -> Result<(), ()> { + visitor: &mut dyn AnyTrait<'ctx>, + hint: <Y as HintMeta>::Hint<'_>, + ) -> ControlFlow<()> { todo!() } fn known( &mut self, - hint: &<Y as Meta>::Hint<'_>, - ) -> Result<<Y as Meta>::Known<'_>, ()> { + hint: &<Y as HintMeta>::Hint<'_>, + ) -> ControlFlow<(), <Y as HintMeta>::Known<'_>> { todo!() } } - impl<'ctx> Meta<'ctx> for Y { + impl<'ctx> HintMeta<'ctx> for Y { type Known<'a> = (); type Hint<'a> = (); |