Crates.io | tagged-serde |
lib.rs | tagged-serde |
version | 0.1.0 |
source | src |
created_at | 2024-03-28 18:49:02.01573 |
updated_at | 2024-03-28 18:49:02.01573 |
description | A procedural macro for serde enums with integer tags |
homepage | |
repository | https://github.com/tweag/nix-remote-rust |
max_upload_size | |
id | 1189265 |
size | 7,413 |
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)
.