Result and Option
Two enums handle absence:
enum Result<T, E> { Ok(T), Err(E) }
enum Option<T> { Some(T), None }
Result is for operations that can fail. Option is for values that may be missing. Both are first-class types you match on.
Error propagation
Chain fallible operations:
fn run() -> Result<(), Box<dyn Error>> {
let n = "42".parse::<i32>()?;
let double = n * 2;
Ok(double)
}
Box<dyn Error> is a boxed trait object that can hold any error type. ? propagates errors up the call chain.