Syntax sugar for enum

Sometimes code may be like on:

enum Variants {
    Variant1(String),
    Variant2(String),
    Variant3(String),
    ...
}

But, I am think this synax would better:

enum Variants(String) {
    Variant1,
    Variant2,
    Variant3,
    ...
}

That's a product type:

struct Variants(String, Variant);

enum Variant {
    Variant1,
    Variant2,
    Variant3,
}
14 Likes

yes, can do something similar to this, but it needs 1 more line compared to my variant syntax

I don't think that complicating the language even more is worth just one line of code.

24 Likes