Rust and Cargo 1 · Code patterns

Propagate errors with ?

Return early with the error when a call fails.

fn read_config(path: &str) -> Result<String, std::io::Error> {
    let text = std::fs::read_to_string(path)?;
    Ok(text)
}

Official Rust and Cargo 1 documentation

More code patterns commands

All code patterns commands · Rust and Cargo 1 cheatsheet

Was this page helpful?