$ snafu

v0.9.0MAJOR UPDATE

An ergonomic error handling library

Downloads: 77.3M
Recent: 11.7M
Versions: 52
Updated: March 2, 2026

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"
}

Linkshttps://crates.io/crates/snafuhttps://docs.rs/snafuhttps://docs.rs/snafu/*/snafu/guide/index.htmlhttps://cirrus-ci.com/github/shepmaster/snafu

https://docs.rs/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

59.8M77.3M

$ VERSION HISTORY

v0.9.0March 2, 2026
v0.8.9September 3, 2025

$ LINKS

$ INSTALL

cargo add snafu

Or add to Cargo.toml: snafu = "0.9.0"