Diffstat (limited to 'src/builtins/walker/hint.rs')
| -rw-r--r-- | src/builtins/walker/hint.rs | 101 |
1 files changed, 84 insertions, 17 deletions
diff --git a/src/builtins/walker/hint.rs b/src/builtins/walker/hint.rs index 42234e9..4392f73 100644 --- a/src/builtins/walker/hint.rs +++ b/src/builtins/walker/hint.rs @@ -4,42 +4,109 @@ //! this module gives a protocol by which a visitor can give a hint //! to the walker about what it is expecting. -use crate::protocol::{Implementer, Protocol}; +use core::marker::PhantomData; -/// Protocol for giving a hint to a walker. -/// -/// A hint is for a particular protocol `P`. -pub struct Hint<P: Meta>(P); +use crate::{ + any::{TypeName, TypeNameable}, + nameable, + protocol::Implementer, +}; /// Meta information for the hint. /// /// This gives the visitor more information to work from when selecting a hint. -pub trait Meta: Protocol { +pub trait Meta<'ctx> { /// Information known by the walker. /// /// This should be information easy to get without changing the state of the walker /// in an irreversable way. - type Known<'a, 'ctx: 'a>; + type Known<'a>; /// Extra information the visitor can give to the walker about what it is expecting. - type Hint<'a, 'ctx: 'a>; + type Hint<'a>; } /// Object implementing the [`Hint`] protocol. -pub trait Object<'ctx, P: Meta> { +pub trait Hint<'ctx, P: Meta<'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<'_, 'ctx>, - ) -> Result<(), ()>; + fn hint(&mut self, visitor: &mut dyn Implementer<'ctx>, hint: P::Hint<'_>) -> Result<(), ()>; /// Ask the walker for information about it's support of the protocol. - fn known(&mut self, hint: &P::Hint<'_, 'ctx>) -> Result<P::Known<'_, 'ctx>, ()>; + fn known(&mut self, hint: &P::Hint<'_>) -> Result<P::Known<'_>, ()>; } -impl<P: Meta> Protocol for Hint<P> { - type Object<'a, 'ctx: 'a> = &'a mut dyn Object<'ctx, P>; +// 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; + } +}; + +#[cfg(test)] +mod test { + use crate::any::LtTypeId; + + use super::*; + + #[test] + fn demo() { + struct X; + struct Y; + + nameable!(['a, 'ctx]: Y => Y); + + impl<'ctx, X> Hint<'ctx, Y> for X { + fn hint( + &mut self, + visitor: &mut dyn Implementer<'ctx>, + hint: <Y as Meta>::Hint<'_>, + ) -> Result<(), ()> { + todo!() + } + + fn known( + &mut self, + hint: &<Y as Meta>::Hint<'_>, + ) -> Result<<Y as Meta>::Known<'_>, ()> { + todo!() + } + } + + impl<'ctx> Meta<'ctx> for Y { + type Known<'a> = (); + + type Hint<'a> = (); + } + + let x = X; + let y: &dyn Hint<Y> = &x; + + fn id<'a, 'ctx, T: ?Sized + TypeNameable<'a, 'ctx>>(x: &T) { + dbg!(LtTypeId::of::<T>()); + } + + id(y); + + todo!(); + } } |