Diffstat (limited to 'src/walk.rs')
| -rw-r--r-- | src/walk.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/walk.rs b/src/walk.rs index 0e02306..692c963 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -19,15 +19,6 @@ pub trait Walk<'ctx, M, E: Effect>: Sized { Self: 'e; } -pub trait WalkerTypes { - type Error: Send + Sync + Debug; - - /// An arbitrary type the walker is left with after walking. - /// - /// Its recommended that this is `Self` if the walker is repeatable. - type Output: Send + Sync; -} - /// Walker for a type. /// /// The `'ctx` lifetime is some lifetime that is longer than `Self`. @@ -37,7 +28,14 @@ pub trait WalkerTypes { /// - 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, E: Effect>: WalkerTypes + Send + Sync { +pub trait Walker<'ctx, E: Effect>: Send + Sync { + type Error: Send + Sync + Debug; + + /// An arbitrary type the walker is left with after walking. + /// + /// Its recommended that this is `Self` if the walker is repeatable. + type Output: Send + Sync; + /// Walk the value. /// /// The walker should send data to the `visitor` as it walks the value. @@ -60,14 +58,14 @@ pub trait WalkerObjSafe<'ctx, E: Effect>: Send { pub type DynWalkerObjSafe<'a, 'ctx, E> = &'a mut (dyn WalkerObjSafe<'ctx, E> + Send + Sync + 'a); -enum DynWalkerState<W: WalkerTypes> { +enum DynWalkerState<'ctx, W: Walker<'ctx, E>, E: Effect> { Walking, Pending(W), Done(W::Output), Err(W::Error), } -pub enum DynWalkerError<W: WalkerTypes> { +pub enum DynWalkerError<'ctx, W: Walker<'ctx, E>, E: Effect> { NeverWalked(W), /// This can only happen if a panic happens furing the walk and is then caught before calling @@ -79,11 +77,11 @@ pub enum DynWalkerError<W: WalkerTypes> { WasWalked(W::Output), } -pub struct DynWalkerAdapter<W: WalkerTypes> { - state: DynWalkerState<W>, +pub struct DynWalkerAdapter<'ctx, W: Walker<'ctx, E>, E: Effect> { + state: DynWalkerState<'ctx, W, E>, } -impl<W: WalkerTypes> DynWalkerAdapter<W> { +impl<'ctx, W: Walker<'ctx, E>, E: Effect> DynWalkerAdapter<'ctx, W, E> { #[inline(always)] pub fn new(walker: W) -> Self { Self { @@ -92,7 +90,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } #[inline(always)] - pub fn finish(self) -> Result<W::Output, DynWalkerError<W>> { + pub fn finish(self) -> Result<W::Output, DynWalkerError<'ctx, W, E>> { match self.state { DynWalkerState::Walking => Err(DynWalkerError::WalkNeverFinished), DynWalkerState::Pending(walker) => Err(DynWalkerError::NeverWalked(walker)), @@ -102,7 +100,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } #[inline(always)] - pub fn into_inner(self) -> Result<W, DynWalkerError<W>> { + pub fn into_inner(self) -> Result<W, DynWalkerError<'ctx, W, E>> { match self.state { DynWalkerState::Walking => Err(DynWalkerError::WalkNeverFinished), DynWalkerState::Pending(walker) => Ok(walker), @@ -112,7 +110,7 @@ impl<W: WalkerTypes> DynWalkerAdapter<W> { } } -impl<'ctx, W: Walker<'ctx, E>, E: Effect> WalkerObjSafe<'ctx, E> for DynWalkerAdapter<W> { +impl<'ctx, W: Walker<'ctx, E>, E: Effect> WalkerObjSafe<'ctx, E> for DynWalkerAdapter<'ctx, W, E> { #[inline(always)] fn walk<'a: 'c, 'b: 'c, 'c>( &'a mut self, |