summaryrefslogtreecommitdiff
path: root/serde_dhall/src/deserialize.rs
diff options
context:
space:
mode:
authorNadrieril2020-10-28 23:40:28 +0000
committerGitHub2020-10-28 23:40:28 +0000
commitf8234684b1129dac84d09adfb24bdc0f98448b9b (patch)
tree1440cfb514fa856718074f2b1ebce801459b5c0c /serde_dhall/src/deserialize.rs
parent70727acbda68e104f60ae1dbbe95adbcec08a628 (diff)
parentaf16e9699799f8cfbd228e2832e1d5df3653116b (diff)
Merge pull request #189 from Nadrieril/serialize
Diffstat (limited to 'serde_dhall/src/deserialize.rs')
-rw-r--r--serde_dhall/src/deserialize.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/serde_dhall/src/deserialize.rs b/serde_dhall/src/deserialize.rs
index 12b4703..0e518ea 100644
--- a/serde_dhall/src/deserialize.rs
+++ b/serde_dhall/src/deserialize.rs
@@ -47,8 +47,6 @@ pub trait FromDhall: Sealed + Sized {
impl<T> Sealed for T where T: serde::de::DeserializeOwned {}
-struct Deserializer<'a>(Cow<'a, SimpleValue>);
-
/// Deserialize a Rust value from a Dhall [`SimpleValue`].
///
/// # Example
@@ -109,6 +107,8 @@ where
}
}
+struct Deserializer<'a>(Cow<'a, SimpleValue>);
+
impl<'de: 'a, 'a> serde::de::IntoDeserializer<'de, Error> for Deserializer<'a> {
type Deserializer = Deserializer<'a>;
fn into_deserializer(self) -> Self::Deserializer {
@@ -171,9 +171,19 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> {
}
}
+ fn deserialize_unit<V>(self, visitor: V) -> crate::Result<V::Value>
+ where
+ V: serde::de::Visitor<'de>,
+ {
+ match self.0.as_ref() {
+ SimpleValue::Record(m) if m.is_empty() => visitor.visit_unit(),
+ _ => self.deserialize_any(visitor),
+ }
+ }
+
serde::forward_to_deserialize_any! {
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
- bytes byte_buf option unit unit_struct newtype_struct seq
+ bytes byte_buf option unit_struct newtype_struct seq
tuple_struct map struct enum identifier ignored_any
}
}