Derive Serialize and Deserialize that delegates to the underlying repr of a C-like enum
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Reynard User f6526998c3
Some checks failed
ci.yml / Update serde-repr to use kade git versions of proc-macro2, quote, syn (push) Failing after 0s
Update serde-repr to use kade git versions of proc-macro2, quote, syn
2026-05-10 18:36:24 +02:00
.github Raise minimum tested compiler to rust 1.85 2026-03-23 19:33:08 -07:00
src Resolve manual_let_else pedantic clippy lint 2025-10-19 14:25:48 -07:00
tests Fill in ignore reasons in all #[ignore] attributes 2024-06-01 22:13:42 -07:00
.gitignore More precise gitignore patterns 2025-01-23 01:35:41 -08:00
Cargo.toml Update serde-repr to use kade git versions of proc-macro2, quote, syn 2026-05-10 18:36:24 +02:00
LICENSE-APACHE Sync license text with rust-lang repos 2022-12-30 12:00:50 -08:00
LICENSE-MIT Initial commit 2019-01-12 12:38:21 -08:00
README.md Update build status badge 2022-12-15 17:52:43 -08:00

Serde repr derive

github crates.io docs.rs build status

This crate provides a derive macro to derive Serde's Serialize and Deserialize traits in a way that delegates to the underlying repr of a C-like enum.

[dependencies]
serde = "1.0"
serde_repr = "0.1"
use serde_repr::{Serialize_repr, Deserialize_repr};

#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
enum SmallPrime {
    Two = 2,
    Three = 3,
    Five = 5,
    Seven = 7,
}

fn main() -> serde_json::Result<()> {
    let j = serde_json::to_string(&SmallPrime::Seven)?;
    assert_eq!(j, "7");

    let p: SmallPrime = serde_json::from_str("2")?;
    assert_eq!(p, SmallPrime::Two);

    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.