Registry / serialization / serde-repr

serde-repr

JSON →
library0.1.20rscratesunverified

Derive Serialize and Deserialize that delegates to the underlying repr of a C-like enum.

# Cargo.toml [dependencies] serde_repr = "0.1.20"
INSTALL
IMPORT
SIG · SERDE-REPR
S
serde-repr
serializationrustv0.1.20
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Serialize_repr
use serde_repr::{Serialize_repr, Deserialize_repr};

Serialize and deserialize C-like enums as their integer representation.

use serde_repr::{Serialize_repr, Deserialize_repr}; #[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)] #[repr(u8)] enum Color { Red = 0, Blue = 1, Green = 2, } fn main() { let color = Color::Blue; let json = serde_json::to_string(&color).unwrap(); assert_eq!(json, "1"); }
Debug
Known issues
gotchaOnly works with C-like enums (no data fields); requires `#[repr(u8/i8/u16/...)]` attribute.
fix
Ensure your enum has no variants with data and has a `#[repr(...)]` attribute.
affects: >=0.1.0
Upgrade
Version history
0.1.20latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Resources
serde-repr — cargo add serde-repr · libregistry