✒️ enser
Enum Serialization with Tag
Usage
Add the following to Cargo.toml
= "0.1.0"
#[derive(Debug, Deserialize, Serialize)]
+ #[enser::enser]
enum MyEnum {
Tbd,
None,
Some(u32),
Named { value: u32 },
}
Rationale
Given the following enum:
When serializing Vec<MyEnum>, the output is:
# serde_yaml
my_enums:
- Tbd
- None
- 123
-
value: 456
# serde_json
When the #[enser::enser] attribute is added:
#[derive(Debug, Deserialize, Serialize)]
+ #[enser::enser]
enum MyEnum { .. }
The output is:
# serde_yaml -- a !Tag is used for each variant
my_enums:
- null
- null
- 123
-
value: 456
# serde_json -- every variant is an object
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.