3 releases
0.1.3 | Nov 3, 2019 |
---|---|
0.1.1 | Sep 7, 2019 |
0.1.0 | Jun 14, 2019 |
#2790 in Rust patterns
Used in librs
4KB
const_type
Define enum
-like const
-types, but with aliases for variants:
use const_type::
{
Const,
};
Const!
{
/// `Bar` is like enum, but variants might have the same value.
/// `usize` is the default type, so `: usize` can be omitted in this case.
pub Bar: usize
{
/// Even Variants could be and should be documented.
A = 1,
B = 2,
C = 2,
D = Bar::A.0,
}
}
This could be used like this:
let Foo: Bar = Bar::B;
Because the enum
is actually a struct
, implementing trait
s or methods canbe doneas usually:
impl Into < usize > for Bar
{
fn into
(
self
)
-> usize
{
self.0 as usize
}
}