1 unstable release
0.1.0 | Mar 28, 2024 |
---|
#22 in #tagged
22 downloads per month
Used in nix-remote
8KB
134 lines
tagged-serde
This crate has a procedural macro for generating serde implementations for enums (a.k.a. tagged unions) with integer tags. In the absence of thorough documentation, the main idea is that
#[derive(TaggedSerde)]
enum MyEnum {
#[tagged_serde = 1]
Str(String),
#[tagged_serde = 42]
Int(i32),
}
will define serde::Serialize
and serde::Deserialize
implementations for MyEnum
so that
MyEnum::Str("hi")
will get serialized as (1, "hi")
and MyEnum::Int(5)
will get
serialized as (42, 5)
.
Dependencies
~255–700KB
~17K SLoC