diff options
author | Nadrieril | 2020-03-21 21:30:30 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-31 21:44:01 +0100 |
commit | 85e2e8ee5e83dadd05b6974ba6c951350cb97a61 (patch) | |
tree | 637043ea591206f695c5b52b6625513de782ddcf /serde_dhall/src/lib.rs | |
parent | 110bfda418b7f1444a2d32b28c515c172a6572a2 (diff) |
Introduce option builder
Diffstat (limited to '')
-rw-r--r-- | serde_dhall/src/lib.rs | 16 |
1 files changed, 5 insertions, 11 deletions
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<Self>; } -fn from_str_with_annot<T>(s: &str, ty: Option<&simple::Type>) -> Result<T> -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<T>(s: &str) -> Result<T> 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<T>(s: &str, ty: &simple::Type) -> Result<T> 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<T>(s: &str) -> Result<T> where T: Deserialize + StaticType, { - from_str_check_type(s, &<T as StaticType>::static_type()) + options::from_str(s).static_type_annotation().parse() } |