1 stable release

Uses old Rust 2015

1.0.196 Feb 15, 2024

#228 in Procedural macros

44 downloads per month

MIT/Apache

310KB
7.5K SLoC

serde_keyed_derive

This is a fork of serde_derive that mirrors the same API but adds an extra attribute called key. This allows you to key your structs with literals other than strings.

Usage

// Do things as normal
#[derive(Serialize, Deserialize)]
struct Message {
    #[serde(key = 1)]
    a: String,
    #[serde(key = 2)]
    b: String,
    #[serde(key = 3)]
    c: String,
    #[serde(key = 4)]
    d: String,
}

For Serde developers

As long as your serializer can handle heterogenous maps, your implementation is already supported. Internally, when keys are detected, the generated code serializes structs as maps.

Limitations

This is experimental, so although it's useable for production, breaking changes may happen.

See https://github.com/serde-rs/serde/pull/2698


lib.rs:

This crate provides Serde's two derive macros.

#
#[derive(Serialize, Deserialize)]
#

Please refer to https://serde.rs/derive.html for how to set this up.

Dependencies

~305–750KB
~18K SLoC