Add partial deserialization support

Only externally tagged, only named fields or unit variants
This commit is contained in:
etwyniel
2019-11-18 09:38:51 +01:00
parent 63d972ab12
commit 81567f15e8
4 changed files with 208 additions and 1 deletions

23
tests/deserialize.rs Normal file
View File

@@ -0,0 +1,23 @@
use miniserde::{json, Deserialize};
use miniserde_enum::Deserialize_enum;
#[test]
fn test_external() {
#[derive(Deserialize_enum, Debug, PartialEq)]
enum External {
// A(i32),
// #[serde(rename = "renamedB")]
// B(i32, String),
C {
x: i32,
},
// D,
}
use External::*;
// let example = r#"[{"A":21},{"renamedB":[42,"everything"]},{"C":{"x":2}},"D"]"#;
let example = r#"[{"C":{"x":2}}]"#;
let actual: Vec<External> = json::from_str(example).unwrap();
// let expected = [A(21), B(42, "everything".to_string()), C { x: 2 }, D];
let expected = vec![C { x: 2 }];
assert_eq!(actual, expected);
}