Returning Result
Functions that can fail return `Result<T, E>`. The caller is required to handle both arms, which prevents the silent error-swallowing common in other languages.
For deeper background, see the canonical Rust learning roadmap for the broader context behind this section.
The ? operator
`?` short-circuits the function and returns the error if a Result is Err. It dramatically reduces match-statement boilerplate when chaining fallible operations.
Defining error types
Real programs define their own error enum and convert sub-errors with the `From` trait. Crates like `thiserror` and `anyhow` reduce the boilerplate further.
When to panic
Panics are for unrecoverable bugs (invariants violated, indexing out of bounds in test code). For anything you might want to recover from, return a Result instead.