Crates.io | serde_keyed_derive |
lib.rs | serde_keyed_derive |
version | 1.0.196 |
source | src |
created_at | 2024-02-15 00:05:57.636123 |
updated_at | 2024-02-15 00:05:57.636123 |
description | Macros 1.1 implementation of #[derive(Serialize, Deserialize)] |
homepage | https://serde.rs |
repository | https://github.com/serde-rs/serde |
max_upload_size | |
id | 1140365 |
size | 317,839 |
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.
// 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,
}
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.
This is experimental, so although it's useable for production, breaking changes may happen.