The ? operator is the single feature that makes Rust error handling pleasant. It turns the verbose match-and-bail pattern into one character.
What ? does
Put ? after a Result (or Option): if it's Ok(v), the expression evaluates to v and execution continues; if it's Err(e), the function returns early with that error. One operator replaces the whole 'match, and on Err return Err' dance — and you can chain several on one line.
It converts errors automatically
Here's the magic that ties back to the Traits track: when the error you're propagating differs from your function's declared error type, ? calls From::from to convert it. Implement From<LowLevelError> for MyError once, and ? seamlessly bubbles low-level errors up as your error type. This is why From for error types is worth the small effort.
? is early-return for errors, with free conversion. On Ok it unwraps and continues; on Err it returns, converting via From on the way out. The happy path reads top to bottom with no error-handling noise, and failures still can't be ignored.The function must return Result
? only works in a function that returns Result (or Option, or another type implementing Try). It needs somewhere to return the error to. main itself can return Result<(), E> so you can use ? right at the top level.