Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions serde_with/src/content/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,6 @@ impl<'de> Visitor<'de> for ContentVisitor<'de> {
Ok(Content::ByteBuf(value))
}

fn visit_unit<F>(self) -> Result<Self::Value, F>
where
F: DeError,
{
Ok(Content::Unit)
}

fn visit_none<F>(self) -> Result<Self::Value, F>
where
F: DeError,
Expand All @@ -267,6 +260,13 @@ impl<'de> Visitor<'de> for ContentVisitor<'de> {
Deserialize::deserialize(deserializer).map(|v| Content::Some(Box::new(v)))
}

fn visit_unit<F>(self) -> Result<Self::Value, F>
where
F: DeError,
{
Ok(Content::Unit)
}

fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -410,11 +410,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
Expand Down Expand Up @@ -798,6 +793,11 @@ where
drop(self);
visitor.visit_unit()
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}
}

impl<'de, E> ContentDeserializer<'de, E> {
Expand Down Expand Up @@ -985,11 +985,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

#[inline]
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
where
Expand All @@ -1009,6 +1004,11 @@ where
}
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

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 tuple
Expand Down Expand Up @@ -1106,11 +1106,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

#[inline]
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
Expand All @@ -1119,6 +1114,11 @@ where
visitor.visit_map(self)
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

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 tuple
Expand Down Expand Up @@ -1231,11 +1231,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, E>
where
V: Visitor<'de>,
Expand Down Expand Up @@ -1590,6 +1585,11 @@ where
{
visitor.visit_unit()
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}
}

impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E> {
Expand Down Expand Up @@ -1759,11 +1759,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

#[inline]
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
where
Expand All @@ -1783,6 +1778,11 @@ where
}
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

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 tuple
Expand Down Expand Up @@ -1880,11 +1880,6 @@ where
{
type Error = E;

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

#[inline]
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
Expand All @@ -1893,6 +1888,11 @@ where
visitor.visit_map(self)
}

#[inline]
fn is_human_readable(&self) -> bool {
self.is_human_readable
}

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 tuple
Expand Down Expand Up @@ -1969,25 +1969,39 @@ where
self.deserialize_map(visitor)
}

fn deserialize_enum<V>(
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
match visitor.__private_visit_untagged_option(self) {
Ok(value) => Ok(value),
Err(()) => Self::deserialize_other(),
}
}

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_unit()
}

fn deserialize_unit_struct<V>(
self,
name: &'static str,
variants: &'static [&'static str],
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
for entry in self.0 {
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
return visitor.visit_enum(EnumDeserializer::new(key, Some(value), self.2));
}
}
visitor.visit_unit()
}

Err(DeError::custom(format_args!(
"no variant of enum {} found in flattened data",
name
)))
fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_newtype_struct(self)
}

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
Expand Down Expand Up @@ -2020,39 +2034,25 @@ where
})
}

fn deserialize_newtype_struct<V>(self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_newtype_struct(self)
}

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
match visitor.__private_visit_untagged_option(self) {
Ok(value) => Ok(value),
Err(()) => Self::deserialize_other(),
}
}

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_unit()
}

fn deserialize_unit_struct<V>(
fn deserialize_enum<V>(
self,
_name: &'static str,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
visitor.visit_unit()
for entry in self.0 {
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
return visitor.visit_enum(EnumDeserializer::new(key, Some(value), self.2));
}
}

Err(DeError::custom(format_args!(
"no variant of enum {} found in flattened data",
name
)))
}

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
Expand Down
16 changes: 8 additions & 8 deletions serde_with/src/content/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ where
type SerializeStruct = StructSerialize<E>;
type SerializeStructVariant = StructVariantSerialize<E>;

fn is_human_readable(&self) -> bool {
self.is_human_readable
}

fn serialize_bool(self, v: bool) -> Result<Content, E> {
Ok(Content::Bool(v))
}
Expand Down Expand Up @@ -385,6 +381,10 @@ where
error: PhantomData,
})
}

fn is_human_readable(&self) -> bool {
self.is_human_readable
}
}

pub(crate) struct SeqSerialize<E> {
Expand Down Expand Up @@ -540,10 +540,6 @@ where
Ok(())
}

fn end(self) -> Result<Content, E> {
Ok(Content::Map(self.entries))
}

fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), E>
where
K: Serialize + ?Sized,
Expand All @@ -554,6 +550,10 @@ where
self.entries.push((key, value));
Ok(())
}

fn end(self) -> Result<Content, E> {
Ok(Content::Map(self.entries))
}
}

pub(crate) struct StructSerialize<E> {
Expand Down
Loading
Loading