Diffstat (limited to 'src/walk.rs')
| -rw-r--r-- | src/walk.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/walk.rs b/src/walk.rs index 9eda9d8..88f3287 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,7 +1,7 @@ // pub mod protocols; // pub mod walkers; -use crate::protocol::Visitor; +use crate::protocol::{ControlFlowFor, Effect, Visitor}; /// A type that can be walked. pub trait Walk<'ctx>: Sized { @@ -9,6 +9,10 @@ pub trait Walk<'ctx>: Sized { type Walker: Walker<'ctx> + From<Self>; } +pub fn into_walker<'ctx, T: Walk<'ctx>>(value: T) -> T::Walker { + <T as Walk<'ctx>>::Walker::from(value) +} + /// Walker for a type. /// /// The `'ctx` lifetime is some lifetime that is longer than `Self`. @@ -19,7 +23,8 @@ pub trait Walk<'ctx>: Sized { /// - Call [Self::walk()] to walk the value. Data will be sent to the provided /// visitor. pub trait Walker<'ctx> { - /// Error that can happen while walking the value. + type Effect: Effect; + type Error; /// An arbitrary type the walker is left with after walking. @@ -30,5 +35,9 @@ pub trait Walker<'ctx> { /// Walk the value. /// /// The walker should send data to the `visitor` as it walks the value. - fn walk(self, visitor: Visitor<'_, 'ctx>) -> Result<Self::Output, Self::Error>; + #[must_use] + fn walk<'a>( + self, + visitor: &'a mut Visitor<'ctx>, + ) -> ControlFlowFor<'a, Self::Effect, Self::Output, Self::Error>; } |