summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authorRudi Floren <rudi.floren@gmail.com>2023-03-02 06:01:26 +0100
committerGitHub <noreply@github.com>2023-03-01 23:01:26 -0600
commit096d851f6d878c2c727f530ccc5749b4d8be2ab0 (patch)
tree15b73f2eb25790ebfaa0c43f998246a5b4267ccb /src/de
parent849cca77d541915552aa44e8cfdbbf90d2ff2042 (diff)
Improve support unit types (#76)
* fix unit type serialization issue `()` and `A` returned a no key error previously. This is very unergonimic if you just have a trait bound for Serialize and want to generate an empty querystring `?` * add support for deserializing unit structs * Comment updates for serializer methods
Diffstat (limited to 'src/de')
-rw-r--r--src/de/mod.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/de/mod.rs b/src/de/mod.rs
index fd34131..ef9cd76 100644
--- a/src/de/mod.rs
+++ b/src/de/mod.rs
@@ -221,10 +221,14 @@ impl<'a> QsDeserializer<'a> {
impl<'de> de::Deserializer<'de> for QsDeserializer<'de> {
type Error = Error;
- fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value>
+ fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value>
where
V: de::Visitor<'de>,
{
+ if self.iter.next().is_none() {
+ return visitor.visit_unit();
+ }
+
Err(Error::top_level("primitive"))
}
@@ -572,6 +576,16 @@ impl<'de> de::Deserializer<'de> for LevelDeserializer<'de> {
}
}
+ fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'de>,
+ {
+ match self.0 {
+ Level::Flat(ref x) if x == "" => visitor.visit_unit(),
+ _ => Err(de::Error::custom("expected unit".to_owned())),
+ }
+ }
+
fn deserialize_enum<V>(
self,
name: &'static str,
@@ -646,7 +660,6 @@ impl<'de> de::Deserializer<'de> for LevelDeserializer<'de> {
string
bytes
byte_buf
- unit
unit_struct
// newtype_struct
tuple_struct