Diffstat (limited to 'src/walk.rs')
| -rw-r--r-- | src/walk.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/walk.rs b/src/walk.rs index 582af96..f0c5c65 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,18 +1,25 @@ pub mod walkers; use crate::{ - effect::{Effect, Yield}, + effect::{Effect, Future}, protocol::Visitor, }; /// A type that can be walked. -pub trait Walk<'ctx>: Sized { +pub trait Walk<'ctx>: WalkerTypes<'ctx> + Sized { /// The walker for the type. - type Walker: Walker<'ctx> + From<Self>; + type Walker<E: Effect<'ctx>>: Walker<'ctx, Error = Self::Error, Output = Self::Output, Effect = E>; + + fn into_walker<E: Effect<'ctx>>(self) -> Self::Walker<E>; } -pub fn into_walker<'ctx, T: Walk<'ctx>>(value: T) -> T::Walker { - <T as Walk<'ctx>>::Walker::from(value) +pub trait WalkerTypes<'ctx> { + type Error: Send; + + /// An arbitrary type the walker is left with after walking. + /// + /// Its recommended that this is `Self` if the walker is repeatable. + type Output: Send; } /// Walker for a type. @@ -24,25 +31,16 @@ pub fn into_walker<'ctx, T: Walk<'ctx>>(value: T) -> T::Walker { /// - Call [From::from()] with a value to be walked to make a walker. /// - Call [Self::walk()] to walk the value. Data will be sent to the provided /// visitor. -pub trait Walker<'ctx> { - type Effect: Effect<'ctx, Result<Self::Output, Self::Error>>; - - type Error; - - /// An arbitrary type the walker is left with after walking. - /// - /// Its recommended that this is `Self` if the walker is repeatable. - type Output; +pub trait Walker<'ctx>: WalkerTypes<'ctx> + Send { + type Effect: Effect<'ctx>; /// Walk the value. /// /// The walker should send data to the `visitor` as it walks the value. - #[must_use] fn walk<'a>( self, - visitor: Visitor<'a, 'ctx, Self::Effect>, - ) -> Yield<'a, 'ctx, Result<Self::Output, Self::Error>, Self::Effect> + visitor: Visitor<'a, 'ctx>, + ) -> Future<'a, 'ctx, Result<Self::Output, Self::Error>, Self::Effect> where - Self: 'a, - 'ctx: 'a; + Self: 'a; } |