Skip to main content

Crate enum_repr_conv

Crate enum_repr_conv 

Source
Expand description

§enum_repr_conv

enum_repr_conv is a proc-macro library that provides a convenient attribute-style repr_conv() macro to specify a primitive integer type used for representing variants of the annotated fieldless enum as values of this type.

§Description

enum_repr_conv bridges the gap between C-style enums and fieldless enums in Rust that can be represented using a chosen primitive integer type. It implements conversions from enum variants into integer values (infallible through std::convert::From) and vice versa (fallible through std::convert::TryFrom). This functionality is provided via repr_conv(<type>) macro that mimics the syntax and behavior of repr(u*)/repr(i*) data layout attributes but additionally provides practical and sensible implementations of common conversion traits.

Attribute Macros§

repr_conv
An attribute macro that mimics the syntax and behavior of repr(u*)/repr(i*) but additionally implements std::convert::From and std::convert::TryFrom traits to provide practical and sensible conversions between annontated enum variants and respective integer values.