Return a compatible `Result` when using the question-mark operator.
Section: Common error patterns
Use `?` with a fallible function
rust
rust
use std::fs;
fn load() -> std::io::Result<String> {
let content = fs::read_to_string("Cargo.toml")?;
Ok(content)
}Explanation
A common mistake is using `?` in a function that does not return a compatible `Result` or `Option`.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Common error patterns