expression
Convert raw input into validated domain commands
Parsing at the boundary separates external representation from internal operations. Reject unknown input once and dispatch on a typed command rather than interpreting strings throughout the application. This tiny parser accepts exactly two literal commands; it is not an authorization system or a shell interpreter. Expected result (NOT RUN): Ok(Show) Err("unknown command") Common mistake: Allowing unchecked strings to become internal actions or confusing validation with authorization. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn parse(raw: &str) -> Result<Command, &'static str>Working Example
Example Snippetrust
#[derive(Debug)]enum Command { Show, Quit }fn parse(raw: &str) -> Result<Command, &'static str> { match raw { "show" => Ok(Command::Show), "quit" => Ok(Command::Quit), _ => Err("unknown command") }}fn main() { println!("{:?}", parse("show")); println!("{:?}", parse("delete"));}