1 个不稳定版本
0.1.0 | 2019 年 10 月 26 日 |
---|
#2444 in 数据结构
4KB
const_enum_map
从枚举句柄获取 const 值
示例
use const_enum_map::{ConstKey,const_enum_map};
fn item0() -> &'static str {
"item0"
}
fn item1() -> &'static str {
"item1"
}
const_enum_map! {
Foo => fn()->&'static str,
Item0 => item0,
Item1 => item1
}
fn main() {
assert_eq!(Foo::Item0.get()(), "item0");
assert_eq!(Foo::Item1.get(), Foo::Item1.get());
assert_eq!(Foo::value_list(), Foo::value_list());
}
许可证:MIT
lib.rs
:
从枚举句柄获取 const 值
示例
use const_enum_map::{ConstKey,const_enum_map};
fn item0() -> &'static str {
"item0"
}
fn item1() -> &'static str {
"item1"
}
const_enum_map! {
Foo => fn()->&'static str,
Item0 => item0,
Item1 => item1
}
fn main() {
assert_eq!(Foo::Item0.get()(), "item0");
assert_eq!(Foo::Item1.get(), Foo::Item1.get());
assert_eq!(Foo::value_list(), Foo::value_list());
}