expression
Represent mutually exclusive states with an enum
A collection of independent flags and optional strings can represent contradictory states. An enum gives each alternative its own required data. This example models only mutually exclusive status values; it does not by itself enforce legal transitions or validate the contents of a tracking code. Expected result (NOT RUN): pending T42 address missing Common mistake: Combining sent and failed Boolean flags with optional tracking and reason fields. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
enum Delivery { Pending, Sent { tracking: String }, Failed { reason: String } }Working Example
Example Snippetrust
enum Delivery { Pending, Sent { tracking: String }, Failed { reason: String } }fn label(delivery: &Delivery) -> &str { match delivery { Delivery::Pending => "pending", Delivery::Sent { tracking } => tracking, Delivery::Failed { reason } => reason, }}fn main() { let items = [Delivery::Pending, Delivery::Sent { tracking: "T42".into() }, Delivery::Failed { reason: "address missing".into() }]; for item in &items { println!("{}", label(item)); }}