mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 10:11:01 +00:00
Merge pull request #1874 from dtolnay/flatunit
Support flattening a Unit
This commit is contained in:
@@ -2763,6 +2763,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
visitor.visit_unit()
|
||||||
|
}
|
||||||
|
|
||||||
forward_to_deserialize_other! {
|
forward_to_deserialize_other! {
|
||||||
deserialize_bool()
|
deserialize_bool()
|
||||||
deserialize_i8()
|
deserialize_i8()
|
||||||
@@ -2780,7 +2787,6 @@ where
|
|||||||
deserialize_string()
|
deserialize_string()
|
||||||
deserialize_bytes()
|
deserialize_bytes()
|
||||||
deserialize_byte_buf()
|
deserialize_byte_buf()
|
||||||
deserialize_unit()
|
|
||||||
deserialize_unit_struct(&'static str)
|
deserialize_unit_struct(&'static str)
|
||||||
deserialize_seq()
|
deserialize_seq()
|
||||||
deserialize_tuple(usize)
|
deserialize_tuple(usize)
|
||||||
|
|||||||
@@ -1124,7 +1124,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||||
Err(Self::bad_type(Unsupported::Unit))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||||
|
|||||||
@@ -1967,6 +1967,29 @@ fn test_flatten_map_twice() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_flatten_unit() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct Response<T> {
|
||||||
|
#[serde(flatten)]
|
||||||
|
data: T,
|
||||||
|
status: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Response {
|
||||||
|
data: (),
|
||||||
|
status: 0,
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::Map { len: None },
|
||||||
|
Token::Str("status"),
|
||||||
|
Token::U64(0),
|
||||||
|
Token::MapEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flatten_unsupported_type() {
|
fn test_flatten_unsupported_type() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user