Enums are really powerful!
Associated values: You can store custom values in an enum.
|
|
Raw values: You can store raw values in an enum. This can be especially useful if you are trying to wrap a reference type like a String (see below) in a value type (enum).
|
|
There is so much more (recursive enums, putting methods inside enums, unwrapping enums, ..)! Enums can be used for so much more than just “options”. One cool thing I’ve seen enums used for before is controlling a C state machine.
Originally published 04/10/2021 @ https://pittcsc.org/ Discord
Published here on 09/08/2022. Blog published date reflects the original date of publication.