# [−]Keyword enum

For defining enumerations.

Enums in Rust are similar to those of other compiled languages like C, but have important differences that make them considerably more powerful. What Rust calls enums are more commonly known as Algebraic Data Types if you're coming from a functional programming background. The important detail is that each enum variant can have data to go along with it.

    enum SimpleEnum {
        FirstVariant,
        SecondVariant,
        ThirdVariant,
    }

    enum Location {
        Unknown,
        Anonymous,
        Known(Coord),
    }

    enum ComplexEnum {
        Nothing,
        Something(u32),
        LotsOfThings {
            usual_struct_stuff: bool,
            blah: String,
        }
    }

    enum EmptyEnum { }Run

The first enum shown is the usual kind of enum you'd find in a C-style language. The second shows off a hypothetical example of something storing location data, with `Coord` being any other type that's needed, for example a struct. The third example demonstrates the kind of data a variant can store, ranging from nothing, to a tuple, to an anonymous struct.

Instantiating enum variants involves explicitly using the enum's name as its namespace, followed by one of its variants. `SimpleEnum::SecondVariant` would be an example from above. When data follows along with a variant, such as with rust's built-in `Option` type, the data is added as the type describes, for example `Option::Some(123)`. The same follows with struct-like variants, with things looking like `ComplexEnum::LotsOfThings { usual_struct_stuff: true, blah: "hello!".to_string(), }`. Empty Enums are similar to () in that they cannot be instantiated at all, and are used mainly to mess with the type system in interesting ways.

For more information, take a look at the Rust Book or the Reference

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)