From 85e2e8ee5e83dadd05b6974ba6c951350cb97a61 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 21 Mar 2020 21:30:30 +0000 Subject: Introduce option builder --- serde_dhall/src/lib.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'serde_dhall/src/lib.rs') diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 4b1a689..5b8f470 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -169,6 +169,8 @@ //! [serde::Deserialize]: https://docs.serde.rs/serde/trait.Deserialize.html mod error; +/// Finer-grained control over deserializing Dhall +pub mod options; mod serde; /// Serde-compatible values and their type pub mod simple; @@ -198,14 +200,6 @@ pub trait Deserialize: sealed::Sealed + Sized { fn from_dhall(v: &Value) -> Result; } -fn from_str_with_annot(s: &str, ty: Option<&simple::Type>) -> Result -where - T: Deserialize, -{ - let val = Value::from_str_with_annot(s, ty)?; - T::from_dhall(&val) -} - /// Deserialize an instance of type `T` from a string of Dhall text. /// /// This will recursively resolve all imports in the expression, and @@ -216,7 +210,7 @@ pub fn from_str(s: &str) -> Result where T: Deserialize, { - from_str_with_annot(s, None) + options::from_str(s).parse() } /// Deserialize an instance of type `T` from a string of Dhall text, @@ -228,7 +222,7 @@ pub fn from_str_check_type(s: &str, ty: &simple::Type) -> Result where T: Deserialize, { - from_str_with_annot(s, Some(ty)) + options::from_str(s).type_annotation(ty).parse() } /// Deserialize an instance of type `T` from a string of Dhall text, @@ -241,5 +235,5 @@ pub fn from_str_auto_type(s: &str) -> Result where T: Deserialize + StaticType, { - from_str_check_type(s, &::static_type()) + options::from_str(s).static_type_annotation().parse() } -- cgit v1.2.3