Topic
Enums
An enum defines a type that can be exactly one of a fixed set of values. Each option is called a variant. Variants can hold no data, tuple-like data, or struct-like named fields - all in the same enum. This makes enums more powerful than simple flags. You use match to run different code depending on which variant is active.
Quick Reference
ConceptWhat it means
enumA custom type where only ONE value is active at a time.
VariantOne of the possible values inside an enum.
EnumName::VariantTwo colons (::) connect the enum name to the variant you picked.
DiscriminatorA number Rust assigns to each variant (starting at 0). You can set your own.
matchA way to say "if this variant, do this; if that variant, do that."
_ catch-allAn underscore arm in match that handles every variant not named explicitly.
TermWhat it meansWhen you use it
enumA custom type where only ONE value is active at a timeWhen a value can only be one of a fixed set of states
VariantOne of the possible values inside an enumThe specific state an enum instance holds right now
EnumName::VariantTwo colons (::) connect the enum name to the variant you pickedEvery time you create or match against an enum value
DiscriminatorA number Rust assigns to each variant, starting at 0When storing an enum value as a number, like saving state on-chain
matchA way to run different code for each variantWhen your code must respond differently depending on which variant is active
_ catch-allAn underscore arm that handles every variant not named explicitlyWhen you only care about a few variants and want to ignore the rest