Skip to content

panicbit/derive_constructor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages