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

```rust use miniserde::{Deserialize, json}; use miniserdeenum::Deserializeenum;

[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 actual: Vec = json::fromstr(example).unwrap(); let expected = [A(21), B(42, "everything".tostring()), C { x: 2 }, D]; assert_eq!(actual, expected); ```

Serializing an internally tagged enum

```rust use miniserde::{json, Serialize}; use miniserdeenum::Serializeenum;

[serde(tag = "type")]

[derive(Serialize_enum)]

enum Internal { A, #[serde(rename = "renamedB")] B, C { x: i32, }, } use Internal::*;

let example = [A, B, C { x: 2 }]; let actual = json::tostring(&example[..]); let expected = r#"[{"type":"A"},{"type":"renamedB"},{"type":"C","x":2}]"#; asserteq!(actual, expected); ```

More examples can be found in the tests directory.

TODO


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.