Crate serde_short

Crate serde_short 

Source
Expand description

Derive Serialize and Deserialize that uses short enum representation for C enum.

A small variant of the serde-repr (99% of the code is simple a copy/paste)

§Examples

use serde_short::{Serialize_short, Deserialize_short};

#[derive(Serialize_short, Deserialize_short, PartialEq, Debug)]
#[repr(C)]
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(())
}

Derive Macros§

Deserialize_short
Serialize_short