This crate provides an attribute macro to associate struct-type constants with enum variants.
 = "0.1"
#[const_table] on an enum with at least two variants, where
- the first has named fields and defines the type of the associated constants, and
- all following have discriminant expressions of that type:
This expands to the following:
Note the automatically inserted
derive attributes. You may place a different
repr attribute as normal,
u64 are supported; an implementation of
TryFrom<T> is provided, where
repr type. You may also
derive additional traits on the enum.
Any attributes placed on the first variant will be placed on the corresponding struct in the expanded code.
Also, note that the macro places the discriminant expressions inside a scope that imports all variants of your enum. This makes it convenient to make the values refer to each other, e.g. in a graph-like structure.
Because the macro implements
Deref for your enum, you can access fields of the target type like
Planet::iter() gives a
DoubleEndedIterator over all variants in declaration order, and
the total number of variants.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.