My program receives commands from the user in the form of numbers: let command: int. That command is supposed to be one of enum values:
enum Command {
Launch,
Stop,
}
How do I convert the command integer to a Command enum? Once I've converted the type from integer to enum, how do I exhaustively match that enum and handle the possibility that command's value is beyond the Command's range of values? Look at the code:
match command { // command has `enum Command` type here already
Launch => { /* ... */ }
Stop => { /* ... */ }
_ => { /* ... */ } // command is user input, so it can have any value, but Rust will yell "unreachable pattern" here
}