Skip to content

Commit

Permalink
Merge pull request #1555 from serde-rs/int
Browse files Browse the repository at this point in the history
Allow integer key in untagged flattened map
  • Loading branch information
dtolnay committed Jun 23, 2019
2 parents dbd67c6 + afb1754 commit 629802f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions serde/src/private/de.rs
Expand Up @@ -1420,6 +1420,7 @@ mod content {
Content::ByteBuf(v) => visitor.visit_byte_buf(v),
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
Content::U8(v) => visitor.visit_u8(v),
Content::U64(v) => visitor.visit_u64(v),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand Down Expand Up @@ -2123,6 +2124,7 @@ mod content {
Content::ByteBuf(ref v) => visitor.visit_bytes(v),
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
Content::U8(v) => visitor.visit_u8(v),
Content::U64(v) => visitor.visit_u64(v),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand Down
28 changes: 28 additions & 0 deletions test_suite/tests/test_macros.rs
Expand Up @@ -1466,6 +1466,34 @@ fn test_internally_tagged_struct_with_flattened_field() {
);
}

#[test]
fn test_untagged_enum_with_flattened_integer_key() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Untagged {
Variant {
#[serde(flatten)]
map: BTreeMap<u64, String>,
},
}

assert_tokens(
&Untagged::Variant {
map: {
let mut map = BTreeMap::new();
map.insert(100, "BTreeMap".to_owned());
map
},
},
&[
Token::Map { len: None },
Token::U64(100),
Token::Str("BTreeMap"),
Token::MapEnd,
],
);
}

#[test]
fn test_enum_in_untagged_enum() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down

0 comments on commit 629802f

Please sign in to comment.