Enums are a tool to express a limited amout of option for a value. Right now the baking type is not important, however there is an interesting exception to define a integer and assign manually a value.
I propose to extend this concept to generic types like this:
const MyVals = enum(f64) {
small = 0.01,
med = 11,
high = 1e32
};
This behaviour can be replicated currenty with a get function, however I find it error prone.
const MyVals = enum {
small,
med,
high,
fn get(self: @This()) f64 {
return switch(self) {
.small => 0.01,
.med => 11,
.high => 1e32,
};
}
};
Also It could be useful to allow assignement:
const x: MyVals = .small;
var y:f64 = x;
I tried to search for previous issues, but I couldn't find a similar proposal.
Is this something that could be added to the language?