From c89dd73fd069ad79ca55dee463ad5d101aff9c85 Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Thu, 18 Jul 2024 21:34:16 +0200 Subject: [PATCH 1/3] Add missing visitor methods --- serde/src/de/mod.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index d6b9f5ab4..ee6359292 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -1630,6 +1630,17 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::Unit, &self)) } + /// The input contains a unit struct. + /// + /// The default implementation forwards to `visit_unit`. + fn visit_unit_struct(self, name: &'static str) -> Result + where + E: Error, + { + let _ = name; + self.visit_unit() + } + /// The input contains a newtype struct. /// /// The content of the newtype struct may be read from the given @@ -1655,6 +1666,27 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::Seq, &self)) } + /// The input contains a tuple. + /// + /// The default implementation forwards to `visit_seq`. + fn visit_tuple(self, tup: A) -> Result + where + A: SeqAccess<'de>, + { + self.visit_seq(tup) + } + + /// The input contains a tuple struct. + /// + /// The default implementation forwards to `visit_seq`. + fn visit_tuple_struct(self, name: &'static str, tup: A) -> Result + where + A: SeqAccess<'de>, + { + let _ = name; + self.visit_seq(tup) + } + /// The input contains a key-value map. /// /// The default implementation fails with a type error. @@ -1666,6 +1698,23 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::Map, &self)) } + /// The input contains a struct. + /// + /// The default implementation forwards to `visit_map`. + fn visit_struct( + self, + name: &'static str, + fields: &[&'static str], + data: A, + ) -> Result + where + A: MapAccess<'de>, + { + let _ = name; + let _ = fields; + self.visit_map(data) + } + /// The input contains an enum. /// /// The default implementation fails with a type error. From 18ceaef040e914eb4615dd44dda717f669fd9bc5 Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Sun, 21 Jul 2024 09:58:22 +0200 Subject: [PATCH 2/3] Add `visit_newtype_struct_with_name` --- serde/src/de/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index ee6359292..8ca6f8c98 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -1655,6 +1655,24 @@ pub trait Visitor<'de>: Sized { Err(Error::invalid_type(Unexpected::NewtypeStruct, &self)) } + /// The input contains a newtype struct. + /// + /// `name` is the name of the struct. The content of the newtype struct may + /// be read from the given `Deserializer`. + /// + /// The default implementation forwards to `visit_newtype_struct`. + fn visit_newtype_struct_with_name( + self, + name: &'static str, + deserializer: D, + ) -> Result + where + D: Deserializer<'de>, + { + let _ = name; + self.visit_newtype_struct(deserializer) + } + /// The input contains a sequence of elements. /// /// The default implementation fails with a type error. From ffb9780e1127d63b983762d3c478f9817e1e9ba1 Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Mon, 22 Jul 2024 13:49:14 +0200 Subject: [PATCH 3/3] Add enum methods --- serde/src/de/mod.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 8ca6f8c98..55cb192ba 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -1641,6 +1641,25 @@ pub trait Visitor<'de>: Sized { self.visit_unit() } + /// The input contains a unit variant. + /// + /// The default implementation forwards to `visit_enum`. + fn visit_unit_variant( + self, + name: &'static str, + variant_index: u32, + variant: &'static str, + data: A, + ) -> Result + where + A: EnumAccess<'de>, + { + let _ = name; + let _ = variant_index; + let _ = variant; + self.visit_enum(data) + } + /// The input contains a newtype struct. /// /// The content of the newtype struct may be read from the given @@ -1673,6 +1692,25 @@ pub trait Visitor<'de>: Sized { self.visit_newtype_struct(deserializer) } + /// The input contains a newtype variant. + /// + /// The default implementation forwards to `visit_enum`. + fn visit_newtype_variant( + self, + name: &'static str, + variant_index: u32, + variant: &'static str, + data: A, + ) -> Result + where + A: EnumAccess<'de>, + { + let _ = name; + let _ = variant_index; + let _ = variant; + self.visit_enum(data) + } + /// The input contains a sequence of elements. /// /// The default implementation fails with a type error. @@ -1705,6 +1743,27 @@ pub trait Visitor<'de>: Sized { self.visit_seq(tup) } + /// The input contains a tuple variant. + /// + /// The default implementation forwards to `visit_enum`. + fn visit_tuple_variant( + self, + name: &'static str, + variant_index: u32, + variant: &'static str, + len: usize, + data: A, + ) -> Result + where + A: EnumAccess<'de>, + { + let _ = name; + let _ = variant_index; + let _ = variant; + let _ = len; + self.visit_enum(data) + } + /// The input contains a key-value map. /// /// The default implementation fails with a type error. @@ -1733,6 +1792,27 @@ pub trait Visitor<'de>: Sized { self.visit_map(data) } + /// The input contains a struct variant. + /// + /// The default implementation forwards to `visit_enum`. + fn visit_struct_variant( + self, + name: &'static str, + variant_index: u32, + variant: &'static str, + fields: &[&'static str], + data: A, + ) -> Result + where + A: EnumAccess<'de>, + { + let _ = name; + let _ = variant_index; + let _ = variant; + let _ = fields; + self.visit_enum(data) + } + /// The input contains an enum. /// /// The default implementation fails with a type error.