When to Use a Struct vs an Enum in Rust

Use structs to group related data fields and enums to define a value that must be one of several distinct variants.

Use a struct to group related data fields together, and use an enum to define a type that can be one of several distinct variants. Structs represent objects with multiple properties, while enums represent a value that must be exactly one of a fixed set of options.

// Use a struct for related data
struct User {
    username: String,
    active: bool,
}

// Use an enum for distinct states
enum Status {
    Active,
    Inactive,
    Pending,
}