diff options
author | Nadrieril | 2019-04-18 11:58:21 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-18 11:58:21 +0200 |
commit | bb1f698c23a83f60020a72bb5be1f9a386c60d44 (patch) | |
tree | 20b5787b4bb53c6005ec60226d549ef34f0ceb0d /dhall_core/src/visitor.rs | |
parent | 22aa0081d314453bd1bb607384da3ed983dc4364 (diff) |
Start cleaning up the mess of mapping functions
Diffstat (limited to 'dhall_core/src/visitor.rs')
-rw-r--r-- | dhall_core/src/visitor.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/dhall_core/src/visitor.rs b/dhall_core/src/visitor.rs index c123275..c6b7321 100644 --- a/dhall_core/src/visitor.rs +++ b/dhall_core/src/visitor.rs @@ -302,7 +302,7 @@ where } } -pub struct TraverseRefVisitor<F1, F2, F3, F4, F5> { +pub struct TraverseRefWithBindersVisitor<F1, F2, F3, F4, F5> { pub visit_subexpr: F1, pub visit_under_binder: F2, pub visit_note: F3, @@ -312,7 +312,7 @@ pub struct TraverseRefVisitor<F1, F2, F3, F4, F5> { impl<'a, SE, L, N, E, SE2, L2, N2, E2, Err, F1, F2, F3, F4, F5> ExprFFallibleVisitor<'a, SE, SE2, L, L2, N, N2, E, E2> - for TraverseRefVisitor<F1, F2, F3, F4, F5> + for TraverseRefWithBindersVisitor<F1, F2, F3, F4, F5> where SE: 'a, L: 'a, @@ -349,6 +349,44 @@ where } } +pub struct TraverseRefVisitor<F1, F2, F3, F4> { + pub visit_subexpr: F1, + pub visit_note: F2, + pub visit_embed: F3, + pub visit_label: F4, +} + +impl<'a, SE, L, N, E, SE2, L2, N2, E2, Err, F1, F2, F3, F4> + ExprFFallibleVisitor<'a, SE, SE2, L, L2, N, N2, E, E2> + for TraverseRefVisitor<F1, F2, F3, F4> +where + SE: 'a, + L: 'a, + N: 'a, + E: 'a, + L: Ord, + L2: Ord, + F1: FnMut(&'a SE) -> Result<SE2, Err>, + F2: FnOnce(&'a N) -> Result<N2, Err>, + F3: FnOnce(&'a E) -> Result<E2, Err>, + F4: FnMut(&'a L) -> Result<L2, Err>, +{ + type Error = Err; + + fn visit_subexpr(&mut self, subexpr: &'a SE) -> Result<SE2, Self::Error> { + (self.visit_subexpr)(subexpr) + } + fn visit_note(self, note: &'a N) -> Result<N2, Self::Error> { + (self.visit_note)(note) + } + fn visit_embed(self, embed: &'a E) -> Result<E2, Self::Error> { + (self.visit_embed)(embed) + } + fn visit_label(&mut self, label: &'a L) -> Result<L2, Self::Error> { + (self.visit_label)(label) + } +} + pub struct TraverseRefSimpleVisitor<F1> { pub visit_subexpr: F1, } |