Fix internally tagged struct variant containing unit variant containing borrowed string
This commit is contained in:
parent
c68b959696
commit
cda1fc46b0
@ -1082,7 +1082,7 @@ mod content {
|
|||||||
}
|
}
|
||||||
(variant, Some(value))
|
(variant, Some(value))
|
||||||
}
|
}
|
||||||
Content::String(variant) => (Content::String(variant), None),
|
s @ Content::String(_) | s @ Content::Str(_) => (s, None),
|
||||||
other => {
|
other => {
|
||||||
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
||||||
}
|
}
|
||||||
@ -1476,7 +1476,7 @@ mod content {
|
|||||||
}
|
}
|
||||||
(variant, Some(value))
|
(variant, Some(value))
|
||||||
}
|
}
|
||||||
ref s @ Content::String(_) => (s, None),
|
ref s @ Content::String(_) | ref s @ Content::Str(_) => (s, None),
|
||||||
ref other => {
|
ref other => {
|
||||||
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
return Err(de::Error::invalid_type(other.unexpected(), &"string or map"),);
|
||||||
}
|
}
|
||||||
|
@ -695,6 +695,35 @@ fn test_internally_tagged_enum() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_internally_tagged_struct_variant_containing_unit_variant() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum Level {
|
||||||
|
Info,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "action")]
|
||||||
|
pub enum Message {
|
||||||
|
Log { level: Level },
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Message::Log { level: Level::Info },
|
||||||
|
&[
|
||||||
|
Token::Struct { name: "Message", len: 2 },
|
||||||
|
|
||||||
|
Token::Str("action"),
|
||||||
|
Token::Str("Log"),
|
||||||
|
|
||||||
|
Token::Str("level"),
|
||||||
|
Token::BorrowedStr("Info"),
|
||||||
|
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_internally_tagged_borrow() {
|
fn test_internally_tagged_borrow() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
Loading…
Reference in New Issue
Block a user