Diffstat (limited to 'src/walk.rs')
-rw-r--r--src/walk.rs74
1 files changed, 8 insertions, 66 deletions
diff --git a/src/walk.rs b/src/walk.rs
index d93316c..7b2ddc1 100644
--- a/src/walk.rs
+++ b/src/walk.rs
@@ -1,74 +1,16 @@
-use crate::Walker;
+use crate::Visitor;
-/// A type that can be walked once.
-///
-/// A walkable type has one canonical walker type, but other walkers
-/// can operate on the same walkable type. This trait gives the canonical
-/// walker for an owned instance of the value. The `'value` lifetime
-/// is the lifetime of the value itself.
-///
-/// [`WalkableOnce`], [`WalkableMut`], and [`Walkable`] form a family of traits
-/// similar to the [`FnOnce`], [`FnMut`], [`Fn`] family of traits.
-pub trait WalkOnce<'value, 'ctx> {
- /// Error the walker can return during the walk.
+pub trait WalkOnce<'ctx> {
type Error;
+ type Value;
- /// Walker over an instance of the type.
- type Walker<VisitorErr: 'value>: Walker<'value, 'ctx, VisitorErr, Error = Self::Error>;
-
- /// Create a walker over a value of the type.
- ///
- /// Walking over the value is able to transfer ownership to the visitor.
- fn into_walker<VisitorErr: 'value>(self) -> Self::Walker<VisitorErr>;
-}
-
-/// A type that can be walked using a mutable borrow.
-///
-/// This trait gives the canonical walker for a mutably borrowed
-/// instance of the value. The `'value` lifetime is the lifetime of
-/// the value itself. The `'walking` lifetime can be used by
-/// [`Self::ErrorMut`] to reference the value using the passed mutable borrow.
-///
-/// [`WalkableOnce`], [`WalkableMut`], and [`Walkable`] form a family of traits
-/// similar to the [`FnOnce`], [`FnMut`], [`Fn`] family of traits.
-pub trait WalkMut<'value, 'borrow, 'ctx> {
- /// Error the walker can return during the walk.
- type Error;
-
- /// Walker over an instance of the type.
- type Walker<VisitorErr: 'value>: Walker<'value, 'ctx, VisitorErr, Error = Self::Error>
- where
- Self: 'borrow;
-
- fn walker_mut<VisitorErr: 'value>(&'borrow mut self) -> Self::Walker<VisitorErr>;
-}
-
-/// `'borrow` is a lifetime between `'value` and `'ctx`.
-/// `'borrow` is the lifetime self will be borrowed from to make the walker.
-/// This allows references to raise their lifetime to `'ctx`.
-pub trait Walk<'value, 'borrow, 'ctx> {
- type Error;
- type Walker<VisitorErr: 'value>: Walker<'value, 'ctx, VisitorErr, Error = Self::Error>
- where
- Self: 'borrow;
-
- fn walker<VisitorErr: 'value>(&'borrow self) -> Self::Walker<VisitorErr>;
-}
-
-pub fn walker_once<'value, 'ctx, VisitorErr: 'value, W: WalkOnce<'value, 'ctx>>(
- value: W,
-) -> W::Walker<VisitorErr> {
- value.into_walker()
+ fn walk_once(self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error>;
}
-pub fn walker_mut<'borrow, 'value, 'ctx, VisitorErr: 'value, W: WalkMut<'value, 'borrow, 'ctx>>(
- value: &'borrow mut W,
-) -> W::Walker<VisitorErr> {
- value.walker_mut()
+pub trait WalkMut<'borrow, 'ctx>: WalkOnce<'ctx> {
+ fn walk_mut(&'borrow mut self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error>;
}
-pub fn walker<'borrow, 'value, 'ctx, VisitorErr: 'value, W: Walk<'value, 'borrow, 'ctx>>(
- value: &'borrow W,
-) -> W::Walker<VisitorErr> {
- value.walker()
+pub trait Walk<'borrow, 'ctx>: WalkMut<'borrow, 'ctx> {
+ fn walk(&'borrow self, visitor: &mut dyn Visitor<'ctx>) -> Result<Self::Value, Self::Error>;
}