Diffstat (limited to 'src/protocol/visitor/value.rs')
| -rw-r--r-- | src/protocol/visitor/value.rs | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs index 20438bb..ed3a0bd 100644 --- a/src/protocol/visitor/value.rs +++ b/src/protocol/visitor/value.rs @@ -2,17 +2,19 @@ //! //! In some sense, this is the most basic protocol. +use core::ops::ControlFlow; + use crate::{ any::{TypeName, TypeNameable}, - nameable, - protocol::{walker::HintMeta, ControlFlowFor, Effect, SyncEffect, any_t}, hkt::hkt, + nameable, + protocol::{any_t, walker::HintMeta, Effect, SyncEffect, Yield}, }; /// Trait object for the [`Value`] protocol. /// /// Types implementing the [`Value`] protocol will implement this trait. -pub trait Value<'ctx, T, E: Effect<'ctx> = SyncEffect> { +pub trait Value<'ctx, T, E: Effect<'ctx, ControlFlow<(), ()>>> { /// Visit a value of type `T`. /// /// Use this to give a value to a visitor. Its expected that a walker @@ -22,7 +24,9 @@ pub trait Value<'ctx, T, E: Effect<'ctx> = SyncEffect> { /// If a [`ControlFlow::Break`] is returned then the walker /// should stop walking as soon as possible as there has likely been /// and error. - fn visit<'a>(&'a mut self, value: T) -> ControlFlowFor<'a, 'ctx, E> where 'ctx: 'a; + fn visit<'a>(&'a mut self, value: T) -> Yield<'a, 'ctx, ControlFlow<(), ()>, E> + where + 'ctx: 'a; } nameable! { @@ -30,13 +34,13 @@ nameable! { impl [T::Name, E] for dyn Value<'ctx, T, E> + 'a where { T: TypeNameable<'a, 'ctx> + ?Sized, - E: Effect<'ctx>, + E: Effect<'ctx, ControlFlow<(), ()>>, 'ctx: 'a, } impl [T, E] where dyn Value<'ctx, T::Nameable, E> + 'a { T: TypeName<'a, 'ctx> + ?Sized, - E: Effect<'ctx>, + E: Effect<'ctx, ControlFlow<(), ()>>, 'ctx: 'a, } } @@ -44,8 +48,10 @@ nameable! { hkt!((any_t): for<'a, 'ctx> pub KnownHkt => ()); // This enrolls the Value protocol into the walker hint system. -impl<'a, 'ctx: 'a, T, E: Effect<'ctx>> HintMeta<'ctx> for dyn Value<'ctx, T, E> + 'a { - type KnownHkt = KnownHkt<'ctx>; +impl<'a, 'ctx: 'a, T, E: Effect<'ctx, ControlFlow<(), ()>>> HintMeta<'ctx> + for dyn Value<'ctx, T, E> + 'a +{ + type Known = KnownHkt<'ctx>; type Hint = (); } @@ -72,7 +78,10 @@ mod test { fn visit<'a>( &'a mut self, OwnedStatic(value): OwnedStatic<i32>, - ) -> core::ops::ControlFlow<()> where 'ctx: 'a { + ) -> core::ops::ControlFlow<()> + where + 'ctx: 'a, + { self.0 = Some(value); ControlFlow::Continue(()) } @@ -82,7 +91,10 @@ mod test { fn visit<'a>( &'a mut self, BorrowedStatic(value): BorrowedStatic<'ctx, i32>, - ) -> core::ops::ControlFlow<()> where 'ctx: 'a { + ) -> core::ops::ControlFlow<()> + where + 'ctx: 'a, + { self.0 = Some(*value); ControlFlow::Continue(()) } @@ -121,7 +133,10 @@ mod test { fn visit<'a>( &'a mut self, BorrowedMutStatic(value): BorrowedMutStatic<'ctx, String>, - ) -> ControlFlow<()> where 'ctx: 'a { + ) -> ControlFlow<()> + where + 'ctx: 'a, + { self.0 = Some(value); ControlFlow::Continue(()) } @@ -154,7 +169,10 @@ mod test { fn visit<'a>( &'a mut self, BorrowedStatic(value): BorrowedStatic<'ctx, str>, - ) -> ControlFlow<()> where 'ctx: 'a { + ) -> ControlFlow<()> + where + 'ctx: 'a, + { self.0 = Some(value); ControlFlow::Continue(()) } |