Code Example Template
enum Platform {
    Windows,
    MacOS,
}

Deep-Dive System Documentation

Enums: Algebraic Sum Types

Enums (enumerations) allow you to define a type by listing its possible variants. Unlike traditional enums in C/C++, Rust's enums are extremely robust sum types.

Basic Enums

Used to represent mutually exclusive states in logic routing:

enum Platform {
    Windows,
    MacOS,
}

let current_os = Platform::Windows;

Discriminants

Under the hood, Rust stores basic enums as simple numeric integers (discriminants), starting at 0.

enum LogLevel {
    Debug = 10,
    Info = 20,
    Error = 30,
}

Compiler Guarding

The Rust compiler strictly guarantees that you handle all enum variants in match statements, preventing unhandled state bugs completely.

Quick Reference Guide

enum State { Up, Down }
let s = State::Up;