diff options
author | Fintan Halpenny | 2019-09-06 12:43:52 +0200 |
---|---|---|
committer | Fintan Halpenny | 2019-09-06 12:43:52 +0200 |
commit | 4424d3ece5db10527ae446a685a579ae768ef943 (patch) | |
tree | 688d29c25f12c2c5347e3d24db8b9b7fb83c7b04 /dhall_syntax/src/core/import.rs | |
parent | 52c91e08db68e05f760ebfd465b84fe4107731df (diff) | |
parent | bcaeab3b7b114d8782be9589ad673ab9ab8c59fd (diff) |
Merge remote-tracking branch 'origin/master' into fintan/canonicalize
Diffstat (limited to '')
-rw-r--r-- | dhall_syntax/src/core/import.rs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index cc38bb0..da3e99b 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -62,7 +62,7 @@ pub struct Import<SubExpr> { } impl<SE> URL<SE> { - pub fn visit_subexpr<'a, Err, SE2>( + pub fn traverse_ref<'a, Err, SE2>( &'a self, f: impl FnOnce(&'a SE) -> Result<SE2, Err>, ) -> Result<URL<SE2>, Err> { @@ -75,32 +75,56 @@ impl<SE> URL<SE> { headers, }) } + pub fn traverse_mut<'a, Err>( + &'a mut self, + f: impl FnOnce(&'a mut SE) -> Result<(), Err>, + ) -> Result<(), Err> { + if let Some(header) = &mut self.headers { + f(header)?; + } + Ok(()) + } } impl<SE> ImportLocation<SE> { - pub fn visit_subexpr<'a, Err, SE2>( + pub fn traverse_ref<'a, Err, SE2>( &'a self, f: impl FnOnce(&'a SE) -> Result<SE2, Err>, ) -> Result<ImportLocation<SE2>, Err> { use ImportLocation::*; Ok(match self { Local(prefix, path) => Local(*prefix, path.clone()), - Remote(url) => Remote(url.visit_subexpr(f)?), + Remote(url) => Remote(url.traverse_ref(f)?), Env(env) => Env(env.clone()), Missing => Missing, }) } + pub fn traverse_mut<'a, Err>( + &'a mut self, + f: impl FnOnce(&'a mut SE) -> Result<(), Err>, + ) -> Result<(), Err> { + if let ImportLocation::Remote(url) = self { + url.traverse_mut(f)?; + } + Ok(()) + } } impl<SE> Import<SE> { - pub fn visit_subexpr<'a, Err, SE2>( + pub fn traverse_ref<'a, Err, SE2>( &'a self, f: impl FnOnce(&'a SE) -> Result<SE2, Err>, ) -> Result<Import<SE2>, Err> { Ok(Import { mode: self.mode, - location: self.location.visit_subexpr(f)?, + location: self.location.traverse_ref(f)?, hash: self.hash.clone(), }) } + pub fn traverse_mut<'a, Err>( + &'a mut self, + f: impl FnOnce(&'a mut SE) -> Result<(), Err>, + ) -> Result<(), Err> { + self.location.traverse_mut(f) + } } |