Preamble
Good day folks, I'm new here
So if there are some issues regarding me and my behavior please point that out and don't raise hell.
Ask for clarification if you're unsure about anything,
apparently I'm bad at communicating. Or so I'm told.
Also, I'm not very proficient with Rust since I'm not a programmer by trade.
Programming still comes somewhat with the territory as an engineer and electrician.
(So if I paste any "dumb" code, advice is appreciated)
Now let's get to the actual topic:
New plan, see here.
The keyword "every"
That is really just a one trick pony or rather syntactic sugar that you can do with macros (I think) but that's not the point...
So enums are absolutely awesome, I love them.
They are very versatile and perfect for any kind of state or anything else that's definitive.
They can even hold stuff, great!
In conjunction with match
they force you to implement every possibility so you can't get undefined behavior for forgetting something.
And forgetting something, oh boy, that's easy.
So to prevent that I'd like the compiler to yell at me some more.
I often find myself in a situation where I want to do some setup depending on a enum and its variants.
Basically, I want to execute a block for every variant the enum contains and it would be nice if the compiler yells at me if I temper at some point with enum itself without adjusting those blocks.
match
does that, but I'm not aware that there is a native method to do something for every
enum variant there is.
And that's the idea, the every
keyword.
It would look something like this:
enum State {
Solid,
Liquid,
Gas,
Plasma,
}
fn setup() {
//stuff happening
every State{
Solid => todo!(),
Liquid => todo!(),
Gas => todo!(),
Plasma => todo!(),
}
//more stuff gets done
}
What keyword(s) ends up used isn't that important, an instant alternative I could think of would be foreach
.
The functionality is something that could add real value to the language it self.
Granted this is niche, but there is a plethora of macro crates out in the wilds that add this functionality in some form or another.
This just shows that there is a considerable interest in it and worth the effort.
You made it, feel free to give feedback