The Sorting Gate
The simulation is firing mock data logs at your terminal. You must build an iron-clad logic gate to categorize these logs by severity.
1. Defining Choices with Enums
If you use raw text strings to define system states (like "low" or "critical"), a simple typo ("crittical") can crash your entire server. Rust uses enum to enforce strict, predefined choices.
enum Severity {
Low,
Critical,
}
2. The Bulletproof Match
Rust provides match, an upgraded version of the traditional if/else block. The compiler forces you to handle every single variant inside an Enum. If you forget to write logic for a Critical alert, your program will refuse to compile. This guarantees you never miss a system failure.
enum Severity {
Low,
Critical,
}
fn main() {
let mock_log = Severity::Critical;
match mock_log {
Severity::Low => println!("Log ignored."),
Severity::Critical => println!("SYSTEM ALERT: Locking down simulation pod!"),
}
}
Note: Severity::Low and Severity::Critical are variants, not values like strings.