std-type
Result<T, E> — success or error
Ok contains a successful value; Err contains information about a failure. The success and error payloads can have different types. Match allows different actions without panicking. Expected stdout (not executed): Invalid quantity Common mistake: Assuming Err always contains a string or that a Result automatically prints its error.
Formal Syntax & Structure
rust syntaxrust
enum Result<T, E> { Ok(T), Err(E) }Working Example
Example Snippetrust
fn main() { let quantity = "many".parse::<u32>(); match quantity { Ok(n) => println!("{n}"), Err(_) => println!("Invalid quantity") }}