#enums #serde #tagged #integer #tags #procedural #proc-macro

macro tagged-serde

A procedural macro for serde enums with integer tags

1 unstable release

0.1.0 Mar 28, 2024

#23 in #tagged


Used in nix-remote

MIT license

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

~240–690KB
~16K SLoC