Crates.io | derive_constructor |
lib.rs | derive_constructor |
version | 0.1.1 |
source | src |
created_at | 2021-09-26 17:27:32.350705 |
updated_at | 2021-09-26 17:28:36.302117 |
description | Construct enums without naming them |
homepage | |
repository | https://github.com/panicbit/derive_constructor |
max_upload_size | |
id | 456627 |
size | 7,687 |
This crate provides a derive macro Constructor
, which creates a silly trait that mirrors an enum's constructors. It allows constructing an enum without explicitly naming its type.
The generated trait has the same name as the enum but with the suffix 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);
}