Situation Normal: All Fouled Up
SNAFU is a library to easily assign underlying errors into domain-specific errors while adding context.
```rust use snafu::{ResultExt, Snafu}; use std::{fs, io, path::PathBuf};
enum Error { #[snafu(display("Unable to read configuration from {}: {}", path.display(), source))] ReadConfiguration { source: io::Error, path: PathBuf },
#[snafu(display("Unable to write result to {}: {}", path.display(), source))]
WriteResult { source: io::Error, path: PathBuf },
}
type Result
fn processdata() -> Result<()> { let path = "config.toml"; let configuration = fs::readtostring(path).context(ReadConfiguration { path })?; let path = unpackconfig(&configuration); fs::write(&path, b"My complex calculation").context(WriteResult { path })?; Ok(()) }
fn unpack_config(data: &str) -> &str { "/some/path/that/does/not/exist" } ```
Please see the documentation and the user's guide for a full description.