rust-primitive_enum
Little utility for dealing with C-style enums
This crate exports just the single macro primitive_enum!
that defines an enum backed by a user specified primitive
integer type.
The intent is to emulate traditional C-style enums while adding some handy associated functions useful in such contexts (e.g. enumerating over each enum and converting between the underlying types).
Example
extern crate primitive_enum;
primitive_enum!
Expansion
As of the current version, the macro
extern crate primitive_enum;
primitive_enum!
is effectively equivalent to
Doc comments
Starting from version 1.1.0, doc comments are supported.
primitive_enum!
Starting from version 1.1.0 this crate is implemented as a procedural macro to improve space efficiency of the generated code. Prior to version 1.1.0, this crate was implemented as a simple declarative macro.
Default trait
Originally, enums did not automatically get the Default
trait. But starting from version 1.2.0
the enum will automatically derive Default
if you specify #[default]
.
So for example, given
extern crate primitive_enum;
primitive_enum!
the resulting code is effectively eqivalent to
This crate is a clean macro implementation that expands to code shown above and doesn't rely on any outside dependencies or magic.