52 releases

0.9.0 Mar 2, 2026
0.8.9 Sep 3, 2025
0.8.8 Aug 28, 2025
0.8.6 May 28, 2025
0.2.0 Mar 26, 2019

#24 in Rust patterns

Download history 1242361/week @ 2026-01-22 1166720/week @ 2026-01-29 995118/week @ 2026-02-05 964044/week @ 2026-02-12 1148121/week @ 2026-02-19 1326483/week @ 2026-02-26 1397954/week @ 2026-03-05 1190636/week @ 2026-03-12 718756/week @ 2026-03-19 755063/week @ 2026-03-26 730943/week @ 2026-04-02 820881/week @ 2026-04-09 822244/week @ 2026-04-16 818157/week @ 2026-04-23 782304/week @ 2026-04-30 881475/week @ 2026-05-07

3,462,579 downloads per month
Used in 2,626 crates (821 directly)

MIT/Apache

130KB
2K SLoC

SNAFU

Situation Normal: All Fouled Up

crates.io Documentation Build Status

SNAFU is a library to easily assign underlying errors into domain-specific errors while adding context.

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

Please see the documentation and the user's guide for a full description.

Dependencies

~0.1–1.3MB
~28K SLoC