summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
authorNadrieril2020-03-20 11:46:46 +0000
committerNadrieril2020-03-20 12:20:38 +0000
commit4ff536cb593aa022e71042ab4fe008e2381b0680 (patch)
tree08fc691ba174831cb85c0fffa474e58e59a47d8c /dhall/src/syntax/ast
parente28d9e6f2422f47e250304e053238adc458f6a98 (diff)
Remove more unnecessary parens in printer
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/expr.rs4
-rw-r--r--dhall/src/syntax/ast/import.rs20
2 files changed, 22 insertions, 2 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 8023771..b53e6cb 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -258,8 +258,8 @@ impl Expr {
}
// Empty enum to indicate that no error can occur
-enum X {}
-fn trivial_result<T>(x: Result<T, X>) -> T {
+pub(crate) enum X {}
+pub(crate) fn trivial_result<T>(x: Result<T, X>) -> T {
match x {
Ok(x) => x,
Err(e) => match e {},
diff --git a/dhall/src/syntax/ast/import.rs b/dhall/src/syntax/ast/import.rs
index 75d7946..c45fe51 100644
--- a/dhall/src/syntax/ast/import.rs
+++ b/dhall/src/syntax/ast/import.rs
@@ -1,3 +1,5 @@
+use crate::syntax::trivial_result;
+
/// The beginning of a file path which anchors subsequent path components
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum FilePrefix {
@@ -75,6 +77,12 @@ impl<SE> URL<SE> {
headers,
})
}
+ pub fn map_ref<'a, SE2>(
+ &'a self,
+ f: impl FnOnce(&'a SE) -> SE2,
+ ) -> URL<SE2> {
+ trivial_result(self.traverse_ref(|x| Ok(f(x))))
+ }
}
impl<SE> ImportTarget<SE> {
@@ -90,6 +98,12 @@ impl<SE> ImportTarget<SE> {
Missing => Missing,
})
}
+ pub fn map_ref<'a, SE2>(
+ &'a self,
+ f: impl FnOnce(&'a SE) -> SE2,
+ ) -> ImportTarget<SE2> {
+ trivial_result(self.traverse_ref(|x| Ok(f(x))))
+ }
}
impl<SE> Import<SE> {
@@ -103,4 +117,10 @@ impl<SE> Import<SE> {
hash: self.hash.clone(),
})
}
+ pub fn map_ref<'a, SE2>(
+ &'a self,
+ f: impl FnOnce(&'a SE) -> SE2,
+ ) -> Import<SE2> {
+ trivial_result(self.traverse_ref(|x| Ok(f(x))))
+ }
}