From bb1f698c23a83f60020a72bb5be1f9a386c60d44 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 11:58:21 +0200 Subject: Start cleaning up the mess of mapping functions --- dhall_core/src/visitor.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'dhall_core/src/visitor.rs') 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 { +pub struct TraverseRefWithBindersVisitor { pub visit_subexpr: F1, pub visit_under_binder: F2, pub visit_note: F3, @@ -312,7 +312,7 @@ pub struct TraverseRefVisitor { 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 + for TraverseRefWithBindersVisitor where SE: 'a, L: 'a, @@ -349,6 +349,44 @@ where } } +pub struct TraverseRefVisitor { + 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 +where + SE: 'a, + L: 'a, + N: 'a, + E: 'a, + L: Ord, + L2: Ord, + F1: FnMut(&'a SE) -> Result, + F2: FnOnce(&'a N) -> Result, + F3: FnOnce(&'a E) -> Result, + F4: FnMut(&'a L) -> Result, +{ + type Error = Err; + + fn visit_subexpr(&mut self, subexpr: &'a SE) -> Result { + (self.visit_subexpr)(subexpr) + } + fn visit_note(self, note: &'a N) -> Result { + (self.visit_note)(note) + } + fn visit_embed(self, embed: &'a E) -> Result { + (self.visit_embed)(embed) + } + fn visit_label(&mut self, label: &'a L) -> Result { + (self.visit_label)(label) + } +} + pub struct TraverseRefSimpleVisitor { pub visit_subexpr: F1, } -- cgit v1.2.3