nrc / derive-new

derive simple constructor functions for Rust structs
MIT License
525 stars 35 forks source link

Feature Request: `fn new` for enums #60

Open Lucretiel opened 1 year ago

Lucretiel commented 1 year ago

While I see that derive-new can create a collection of constructors for enum variants, it would be convenient for enums that always have a single new constructor, like this:

#[derive(new)]
enum Foo {
    #[new]
    InitialState { data: String },
    SecondState{ data: Vec<u8> }
}

// Produces:

fn new(data: String) -> Foo { Foo::InitialState{data}}