Skip to content

Commit

Permalink
Extend test_internally_tagged_newtype_variant_containing_unit_struct …
Browse files Browse the repository at this point in the history
…to cover structs and seqs
  • Loading branch information
Mingun committed Nov 3, 2020
1 parent 206dfc2 commit aa80468
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
44 changes: 42 additions & 2 deletions serde/src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,26 @@ where
visitor.visit_seq(self.seq)
}

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

fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
// See test_internally_tagged_newtype_variant_containing_unit_struct
visitor.visit_unit()
}

fn deserialize_newtype_struct<V>(
self,
_name: &str,
Expand All @@ -920,7 +940,7 @@ where

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 seq tuple
bytes byte_buf option seq tuple
tuple_struct map struct enum identifier ignored_any
}

Expand Down Expand Up @@ -1366,6 +1386,26 @@ where
visitor.visit_enum(self)
}

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

fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
// See test_internally_tagged_newtype_variant_containing_unit_struct
visitor.visit_unit()
}

fn deserialize_newtype_struct<V>(
self,
_name: &str,
Expand All @@ -1379,7 +1419,7 @@ where

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 seq tuple
bytes byte_buf option seq tuple
tuple_struct map struct identifier ignored_any
}

Expand Down
19 changes: 19 additions & 0 deletions test_suite/tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,25 @@ fn test_internally_tagged_newtype_variant_containing_unit_struct() {
Token::MapEnd,
],
);

assert_de_tokens(
&Message::Info(Info).readable(),
&[
Token::Struct { name: "Message", len: 1 },
Token::Str("topic"),
Token::Str("Info"),
Token::StructEnd,
],
);

assert_de_tokens(
&Message::Info(Info).readable(),
&[
Token::Seq { len: Some(1) },
Token::Str("Info"),
Token::SeqEnd,
],
);
}

#[deny(safe_packed_borrows)]
Expand Down

0 comments on commit aa80468

Please sign in to comment.