How to Use Database Enums in Rust

Define an `enum` to group related variants and use `match` to handle each case safely. This pattern ensures your code handles every possible state without runtime errors.

How to Use Database Enums in Rust

Define an enum to group related variants and use match to handle each case safely. This pattern ensures your code handles every possible state without runtime errors.

enum Status {
    Active,
    Inactive,
    Pending,
}

fn check_status(s: Status) -> &'static str {
    match s {
        Status::Active => "Running",
        Status::Inactive => "Stopped",
        Status::Pending => "Waiting",
    }
}

fn main() {
    let s = Status::Active;
    println!("Status: {}", check_status(s));
}