#constructor #enums #derive #naming #name #construct

derive_constructor

不命名枚举构造函数

2个版本

0.1.1 2021年9月26日
0.1.0 2021年9月26日

#1379 in 过程宏

MIT/Apache

7KB
118

derive-constructor

此crate提供了一个 derive宏 Constructor,该宏创建了一个反映枚举构造函数的silly trait。它允许在不需要显式命名类型的情况下构造枚举。生成的trait与枚举同名,但后缀为Constructor

示例

use derive_constructor::Constructor;

#[derive(Constructor, Debug)]
enum Foo {
    A,
    B(i32)
}

fn main() {
    print_foo(<_>::A);
    print_foo(<_>::B(42));
}

fn print_foo(foo: Foo) {
    println!("{:?}", foo);
}

依赖项

~1.5MB
~38K SLoC