Merge pull request #2436 from Mingun/flatten-ignored-any

Allow to flatten `IgnoredAny`
This commit is contained in:
David Tolnay
2023-07-06 16:35:10 -07:00
committed by GitHub
3 changed files with 34 additions and 3 deletions
+26 -1
View File
@@ -10,7 +10,7 @@
clippy::uninlined_format_args,
)]
use serde::de::{self, MapAccess, Unexpected, Visitor};
use serde::de::{self, IgnoredAny, MapAccess, Unexpected, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::{BTreeMap, HashMap};
@@ -2697,6 +2697,31 @@ fn test_flatten_option() {
);
}
#[test]
fn test_flatten_ignored_any() {
#[derive(Deserialize, PartialEq, Debug)]
struct Outer {
#[serde(flatten)]
inner: IgnoredAny,
}
assert_de_tokens(
&Outer { inner: IgnoredAny },
&[Token::Map { len: None }, Token::MapEnd],
);
assert_de_tokens(
&Outer { inner: IgnoredAny },
&[
Token::Struct {
name: "DoNotMatter",
len: 0,
},
Token::StructEnd,
],
);
}
#[test]
fn test_transparent_struct() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]