miniserde-enum
This crate exposes derive macros for miniserde's Serialize
and Deserialize
traits on enums.
The goal of this crate is to provide enum support like that of Serde for miniserde (see Serde's list of enum representations).
Examples
Deserializing an externally tagged enum
use ;
use Deserialize_enum;
use *;
let example = r#"[{"A":21},{"renamedB":[42,"everything"]},{"C":{"x":2}},"D"]"#;
let actual: = from_str.unwrap;
let expected = ;
assert_eq!;
Serializing an internally tagged enum
use ;
use Serialize_enum;
use *;
let example = ;
let actual = to_string;
let expected = r#"[{"type":"A"},{"type":"renamedB"},{"type":"C","x":2}]"#;
assert_eq!;
More examples can be found in the tests directory.
Limitations
Deserializing internally tagged enums and adjacently tagged enums requires the tag to be the first key in the object, otherwise from_str will return an error.
Additionally, not every enum representation is currently supported (see TODO).
TODO
- Serialization:
Externally tagged enumsInternally tagged enumsUntagged enums- Adjacently tagged enums
- Deserialization
Externally tagged enumsInternally tagged enums- Untagged enums
Adjacently tagged enums