From cd31d3eb311024153ccf1f8187126ad351963456 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Oct 2020 02:18:35 +0100 Subject: feat: Add a `Display` impl for `SimpleType` Fixes https://github.com/Nadrieril/dhall-rust/issues/179 --- serde_dhall/src/value.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'serde_dhall/src/value.rs') 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()) +} -- cgit v1.2.3