enum-repr

Build Status Crates.io Documentation

Generate enum repr conversions compatible with type aliases. Works on no_std.

EnumRepr proc macro takes an type argument and defines two functions for the enum used on: fn repr(&self) -> EnumReprType fn from_repr(x: EnumReprType) -> Option<Self> The real enum discriminant still remains isize.

```rust extern crate enum_repr; extern crate libc;

use libc::*;

use enum_repr::EnumRepr;

[EnumRepr(type = "c_int")]

[derive(Debug, PartialEq)]

pub enum IpProto { IP = IPPROTOIP, IPv6 = IPPROTOIPV6, // … }

fn main() { asserteq!(IpProto::IP.repr(), IPPROTOIP); asserteq!(IpProto::fromrepr(IPPROTOIPV6), Some(IpProto::IPv6)); assert!(IpProto::fromrepr(12345).is_none()); } ```

License

This project is licensed under either of

at your option.