summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2020-10-16 02:18:35 +0100
committerNadrieril2020-10-16 02:18:35 +0100
commitcd31d3eb311024153ccf1f8187126ad351963456 (patch)
treea1a2a40b892165659cd9fcd8b24b9af00bd25450
parent45443aafc6846278988e91b344255b426e2dfe9f (diff)
feat: Add a `Display` impl for `SimpleType`
Fixes https://github.com/Nadrieril/dhall-rust/issues/179
-rw-r--r--CHANGELOG.md2
-rw-r--r--serde_dhall/src/value.rs21
2 files changed, 23 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b6388f..f976b59 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
#### [Unreleased]
+- Add a `Display` impl for `SimpleType` (https://github.com/Nadrieril/dhall-rust/issues/179)
+
#### [0.7.0] - 2020-09-15
- BREAKING CHANGE: Support Dhall v18.0.0
diff --git a/serde_dhall/src/value.rs b/serde_dhall/src/value.rs
index 0f0b256..b26985b 100644
--- a/serde_dhall/src/value.rs
+++ b/serde_dhall/src/value.rs
@@ -290,6 +290,11 @@ impl SimpleType {
),
})
}
+
+ /// Converts back to the corresponding AST expression.
+ pub(crate) fn to_expr(&self) -> Expr {
+ self.to_hir().to_expr(Default::default())
+ }
}
impl Sealed for Value {}
@@ -336,3 +341,19 @@ impl std::fmt::Display for Value {
self.to_expr().fmt(f)
}
}
+
+impl std::fmt::Display for SimpleType {
+ fn fmt(
+ &self,
+ f: &mut std::fmt::Formatter,
+ ) -> std::result::Result<(), std::fmt::Error> {
+ self.to_expr().fmt(f)
+ }
+}
+
+#[test]
+fn test_display_simpletype() {
+ use SimpleType::*;
+ let ty = List(Box::new(Optional(Box::new(Natural))));
+ assert_eq!(ty.to_string(), "List (Optional Natural)".to_string())
+}