mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-24 06:27:59 +00:00
Factor out attr module
Factors out field attribute code into the attr module.
This commit is contained in:
@@ -27,6 +27,16 @@ struct FormatRename {
|
||||
a2: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize, Serialize)]
|
||||
enum SerEnum<A> {
|
||||
Map {
|
||||
a: i8,
|
||||
#[serde(rename(xml= "c", json="d"))]
|
||||
b: A,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let deserialized_value: Default = json::from_str(&"{\"a1\":1,\"a2\":2}").unwrap();
|
||||
@@ -55,3 +65,15 @@ fn test_format_rename() {
|
||||
let deserialized_value = json::from_str("{\"a1\":1,\"a5\":2}").unwrap();
|
||||
assert_eq!(value, deserialized_value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enum_format_rename() {
|
||||
let s1 = String::new();
|
||||
let value = SerEnum::Map { a: 0i8, b: s1 };
|
||||
let serialized_value = json::to_string(&value).unwrap();
|
||||
let ans = "{\"Map\":{\"a\":0,\"d\":\"\"}}";
|
||||
assert_eq!(serialized_value, ans);
|
||||
|
||||
let deserialized_value = json::from_str(ans).unwrap();
|
||||
assert_eq!(value, deserialized_value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user