diff options
author | Nadrieril | 2020-03-08 17:11:34 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-31 21:44:01 +0100 |
commit | 84796fd247eb1a13fcd092a7cd7ec2d587b261bd (patch) | |
tree | 1be14161e1181ae058329f4d6bc29cc9c8409aab /serde_dhall/src/lib.rs | |
parent | 5a5aa49e64197899006751db72e404f4b2292d4e (diff) |
Add SimpleValue type to facilitate deserialization
Diffstat (limited to '')
-rw-r--r-- | serde_dhall/src/lib.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 0a53420..55e098c 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -182,16 +182,19 @@ pub use value::Value; #[doc(hidden)] pub mod value { use dhall::syntax::Builtin; - use dhall::{Normalized, NormalizedExpr, Parsed}; + use dhall::{Normalized, NormalizedExpr, Parsed, SimpleValue}; - use super::de::{Error, Result}; + use super::de::Error; /// A Dhall value #[derive(Debug, Clone, PartialEq, Eq)] pub struct Value(Normalized); impl Value { - pub fn from_str(s: &str, ty: Option<&Value>) -> Result<Self> { + pub fn from_str( + s: &str, + ty: Option<&Value>, + ) -> super::de::Result<Self> { Value::from_str_using_dhall_error_type(s, ty).map_err(Error::Dhall) } fn from_str_using_dhall_error_type( @@ -205,8 +208,10 @@ pub mod value { }; Ok(Value(typed.normalize())) } - pub(crate) fn to_expr(&self) -> NormalizedExpr { - self.0.to_expr() + pub(crate) fn to_simple_value( + &self, + ) -> Result<SimpleValue, NormalizedExpr> { + self.0.to_simple_value() } pub(crate) fn as_normalized(&self) -> &Normalized { &self.0 @@ -241,7 +246,7 @@ pub mod value { impl super::de::sealed::Sealed for Value {} impl super::de::Deserialize for Value { - fn from_dhall(v: &Value) -> Result<Self> { + fn from_dhall(v: &Value) -> super::de::Result<Self> { Ok(v.clone()) } } |