Diffstat (limited to 'src/walk.rs')
| -rw-r--r-- | src/walk.rs | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/walk.rs b/src/walk.rs index 7f8c82a..d93316c 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,4 +1,4 @@ -use crate::{error::WalkerError, Walker}; +use crate::Walker; /// A type that can be walked once. /// @@ -9,17 +9,17 @@ use crate::{error::WalkerError, Walker}; /// /// [`WalkableOnce`], [`WalkableMut`], and [`Walkable`] form a family of traits /// similar to the [`FnOnce`], [`FnMut`], [`Fn`] family of traits. -pub trait WalkOnce<'value, 'ctx: 'value, VisitorErr> { +pub trait WalkOnce<'value, 'ctx> { /// Error the walker can return during the walk. - type ErrorOnce: WalkerError<'value, 'ctx>; + type Error; /// Walker over an instance of the type. - type WalkerOnce: Walker<'value, 'ctx, VisitorErr, Error = Self::ErrorOnce>; + 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(self) -> Self::WalkerOnce; + fn into_walker<VisitorErr: 'value>(self) -> Self::Walker<VisitorErr>; } /// A type that can be walked using a mutable borrow. @@ -31,40 +31,44 @@ pub trait WalkOnce<'value, 'ctx: 'value, VisitorErr> { /// /// [`WalkableOnce`], [`WalkableMut`], and [`Walkable`] form a family of traits /// similar to the [`FnOnce`], [`FnMut`], [`Fn`] family of traits. -pub trait WalkMut<'value, 'ctx: 'value, VisitorErr> { +pub trait WalkMut<'value, 'borrow, 'ctx> { /// Error the walker can return during the walk. - type ErrorMut: WalkerError<'value, 'ctx>; + type Error; /// Walker over an instance of the type. - type WalkerMut: Walker<'value, 'ctx, VisitorErr, Error = Self::ErrorMut>; + type Walker<VisitorErr: 'value>: Walker<'value, 'ctx, VisitorErr, Error = Self::Error> + where + Self: 'borrow; - fn walker_mut(&'value mut self) -> Self::WalkerMut; + 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: 'value, 'ctx: 'borrow, VisitorErr> /*WalkMut<'value, 'ctx, VisitorErr>*/ { - type Error: WalkerError<'value, 'ctx>; - type Walker: Walker<'value, 'ctx, VisitorErr, Error = Self::Error>; +pub trait Walk<'value, 'borrow, 'ctx> { + type Error; + type Walker<VisitorErr: 'value>: Walker<'value, 'ctx, VisitorErr, Error = Self::Error> + where + Self: 'borrow; - fn walker(&'borrow self) -> Self::Walker; + fn walker<VisitorErr: 'value>(&'borrow self) -> Self::Walker<VisitorErr>; } -pub fn walker_once<'value, 'ctx: 'value, VisitorErr, W: WalkOnce<'value, 'ctx, VisitorErr>>( +pub fn walker_once<'value, 'ctx, VisitorErr: 'value, W: WalkOnce<'value, 'ctx>>( value: W, -) -> W::WalkerOnce { +) -> W::Walker<VisitorErr> { value.into_walker() } -pub fn walker_mut<'value, 'ctx: 'value, VisitorErr, W: WalkMut<'value, 'ctx, VisitorErr>>( - value: &'value mut W, -) -> W::WalkerMut { +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 fn walker<'value, 'ctx: 'value, 'root: 'ctx, VisitorErr, W: Walk<'value, 'ctx, 'root, VisitorErr>>( -// value: &'value W, -// ) -> W::Walker { -// value.walker() -// } +pub fn walker<'borrow, 'value, 'ctx, VisitorErr: 'value, W: Walk<'value, 'borrow, 'ctx>>( + value: &'borrow W, +) -> W::Walker<VisitorErr> { + value.walker() +} |