$ snafu
v0.9.0MAJOR UPDATEAn ergonomic error handling library
Latest Update Summary
Crate
Name: snafu New version: 0.9.0 Release date: 2026-03-02T17:56:47.615424Z
Crate readme
Short description SNAFU is a library to easily assign underlying errors into domain-specific errors while adding context.
Long description SNAFU allows you to assign underlying errors to domain-specific errors, providing context in the process. It offers a structured approach to error handling in Rust, ensuring that detailed error information is preserved.
Features • Easily create domain-specific errors • Add contextual information to errors • Supports standard I/O errors
Code Examples Basic usage
use snafu::prelude::*;
use std::{fs, io, path::PathBuf};
#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("Unable to read configuration from {}", path.display()))]
ReadConfiguration { source: io::Error, path: PathBuf },
#[snafu(display("Unable to write result to {}", path.display()))]
WriteResult { source: io::Error, path: PathBuf },
}
type Result<T, E = Error> = std::result::Result<T, E>;
fn process_data() -> Result<()> {
let path = "config.toml";
let configuration = fs::read_to_string(path).context(ReadConfigurationSnafu { path })?;
let path = unpack_config(&configuration);
fs::write(&path, b"My complex calculation").context(WriteResultSnafu { path })?;
Ok(())
}
fn unpack_config(data: &str) -> &str {
"/some/path/that/does/not/exist"
}
Links • https://crates.io/crates/snafu • https://docs.rs/snafu • https://docs.rs/snafu/*/snafu/guide/index.html • https://cirrus-ci.com/github/shepmaster/snafu
Release info
Release version: N/A
Release description N/A
Code Examples N/A
Minor update: 0.8.9 → 0.9.0
$ DOWNLOADS TREND
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add snafuOr add to Cargo.toml: snafu = "0.9.0"