diff options
Diffstat (limited to 'serde_dhall/src')
-rw-r--r-- | serde_dhall/src/value.rs | 21 |
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()) +} |