serde_keyed_derive

Crates.ioserde_keyed_derive
lib.rsserde_keyed_derive
version1.0.196
sourcesrc
created_at2024-02-15 00:05:57.636123
updated_at2024-02-15 00:05:57.636123
descriptionMacros 1.1 implementation of #[derive(Serialize, Deserialize)]
homepagehttps://serde.rs
repositoryhttps://github.com/serde-rs/serde
max_upload_size
id1140365
size317,839
Randolf J. (jun-sheaf)

documentation

https://serde.rs/derive.html

README

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

Commit count: 4135

cargo fmt