summaryrefslogtreecommitdiff
path: root/serde_dhall
diff options
context:
space:
mode:
authorNadrieril2020-10-16 02:18:35 +0100
committerNadrieril2020-10-16 02:18:35 +0100
commitcd31d3eb311024153ccf1f8187126ad351963456 (patch)
treea1a2a40b892165659cd9fcd8b24b9af00bd25450 /serde_dhall
parent45443aafc6846278988e91b344255b426e2dfe9f (diff)
feat: Add a `Display` impl for `SimpleType`
Fixes https://github.com/Nadrieril/dhall-rust/issues/179
Diffstat (limited to 'serde_dhall')
-rw-r--r--serde_dhall/src/value.rs21
1 files changed, 21 insertions, 0 deletions
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())
+}