26
Opinions on this syntax for enums?
(lemm.ee)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
Wait, why literals? Could you not have just Some, without quotes? Or does this syntax imply that enums use these constants as variant tags?
Re: the pipe symbol - i wanted to also use this syntax but have decided against because pipes just looked stranger than commas.
The Idea is that the enum acts as a union, capable of holding any of the member types, It's not that different from using identifiers and when transpiling to rust I will probably only support variants beginning with string literals (or maybe generate them).
The main reason is that I could use type inference to define the variants in a returned anonymous enum.
I like the pipe symbol because it is useful for distinguishing between enums and structs without keywords. And I just personally think it looks better. And allow for pretty anonymous enums like
(|String |Int)
for something that can accept both a string and an integer.