error-concept
anyhow::Result for application boundaries
Combine several fallible operations under a shared application error type. Prefer concrete error types where callers need a stable recovery contract. Requires anyhow = "=1.0.104" in Cargo.toml. See the staged dependency project. Expected stdout (not executed): failed=true Expected stderr: (empty) Expected exit: success Common mistake: Assuming every error type can be converted regardless of thread-safety or lifetime bounds.
Formal Syntax & Structure
rust syntaxrust
anyhow::Result<T>Working Example
Example Snippetrust
fn quantity(text: &str) -> anyhow::Result<u32> { let n: u32 = text.parse()?; Ok(n)}fn main() { println!("failed={}", quantity("bad").is_err());}