derive_constructor

Crates.ioderive_constructor
lib.rsderive_constructor
version0.1.1
sourcesrc
created_at2021-09-26 17:27:32.350705
updated_at2021-09-26 17:28:36.302117
descriptionConstruct enums without naming them
homepage
repositoryhttps://github.com/panicbit/derive_constructor
max_upload_size
id456627
size7,687
(panicbit)

documentation

README

derive-constructor

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.

Example

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);
}
Commit count: 6

cargo fmt