https://github.com/trussed-dev/serde-indexed
Derivation of Serialize and Deserialize that replaces struct keys with numerical indices.
https://github.com/trussed-dev/serde-indexed
cbor no-std rust serde
Last synced: 3 months ago
JSON representation
Derivation of Serialize and Deserialize that replaces struct keys with numerical indices.
- Host: GitHub
- URL: https://github.com/trussed-dev/serde-indexed
- Owner: trussed-dev
- License: apache-2.0
- Created: 2020-01-11T14:31:16.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-06T08:42:15.000Z (4 months ago)
- Last Synced: 2025-07-06T10:42:52.322Z (3 months ago)
- Topics: cbor, no-std, rust, serde
- Language: Rust
- Homepage: https://docs.rs/serde-indexed/
- Size: 47.9 KB
- Stars: 3
- Watchers: 1
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
## serde-indexed
[![crates.io][crates-image]][crates-link]
[![Documentation][docs-image]][docs-link]Derivation of [`Serialize`][serialize] and [`Deserialize`][deserialize] that replaces struct keys with numerical indices.
Primary use case is to handle [CTAP CBOR][ctap-cbor] messages, in particular support for:
- [`skip_serializing_if`][skip-serializing-if] for optional keys
- configurable index `offset`#### Example
```rust
#[derive(Clone, Debug, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct SomeKeys {
pub number: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub option: Option,
pub bytes: [u8; 7],
}
```This was a nice opportunity to learn proc-macros, I roughly followed [`serde-repr`][serde-repr].
To see some generated code, run `cargo expand --test basics`.
[crates-image]: https://img.shields.io/crates/v/serde-indexed.svg?style=flat-square
[crates-link]: https://crates.io/crates/serde-indexed
[docs-image]: https://img.shields.io/badge/docs.rs-api-green?style=flat-square
[docs-link]: https://docs.rs/serde-indexed
[serialize]: https://docs.serde.rs/serde/ser/trait.Serialize.html
[deserialize]: https://docs.serde.rs/serde/de/trait.Deserialize.html
[ctap-cbor]: https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#ctap2-canonical-cbor-encoding-form
[skip-serializing-if]: https://serde.rs/field-attrs.html#skip_serializing_if
[serde-repr]: https://github.com/dtolnay/serde-repr#### License
`serde-indexed` is licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or [MIT License](LICENSE-MIT) at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.