> For the complete documentation index, see [llms.txt](https://bootcamp.openguild.wtf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bootcamp.openguild.wtf/rust-programming-language/basic-rust/common-data-structures.md).

# Common Data Structures

{% embed url="<https://openguild-labs.github.io/open-rust/syllabus/module/1.4-slides.html>" %}

## Enumeration

{% embed url="<https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html>" %}
Learn about Enum in the Rust programming language book
{% endembed %}

<figure><img src="/files/2LnwBIRDAE3N02YL3ICU" alt=""><figcaption><p>Bullet points of the enumeration</p></figcaption></figure>

An enumeration, or enum, is a data type that allows a variable to take on one of several possible values (or states). Each of these possibilities is called a "variant." For example, in Rust, an enum can represent different states of a traffic light with variants such as `Red`, `Yellow`, and `Green`.

```rust
enum Direction {
    Up,
    Down,
    Left,
    Right,
}

fn which_way(go: Direction) -> &'static str {
    match go {
        Direction::Up => "up",
        Direction::Down => "down",
        Direction::Left => "left",
        Direction::Right => "right",
    }
}
```

## Structure

<figure><img src="/files/KO85L8QjnOnWbnQzsMDa" alt=""><figcaption></figcaption></figure>

```rust
struct ShippingBox {
    depth: i32,
    width: i32,
    height: i32,
}

fn main() {
    let my_box = ShippingBox {
        depth: 3,
        width: 2,
        height: 5,
    };

    let tall = my_box.height;
    println!("the box is {:?} units tall", tall);
}
```
