> 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="https://2688244615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqpKohKlriBQm0I9cc9k5%2Fuploads%2FafzfGw5OHxVtweCOOZc2%2FScreenshot%202024-10-29%20at%2013.34.09.png?alt=media&amp;token=252aa2d5-15d3-4d60-9374-967ddf750d4b" 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="https://2688244615-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqpKohKlriBQm0I9cc9k5%2Fuploads%2FzSWnywDp19aSjqPItUh4%2FScreenshot%202024-10-29%20at%2013.37.02.png?alt=media&amp;token=4f0b3228-d0f2-4174-91eb-2e03f6a5badc" 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);
}
```
