51 releases

0.8.9 Sep 3, 2025
0.8.6 May 28, 2025
0.8.5 Sep 23, 2024
0.8.4 Jul 8, 2024
0.2.0 Mar 26, 2019

#25 in Rust patterns

Download history 759826/week @ 2025-09-19 811011/week @ 2025-09-26 809315/week @ 2025-10-03 763968/week @ 2025-10-10 754140/week @ 2025-10-17 813386/week @ 2025-10-24 802015/week @ 2025-10-31 813428/week @ 2025-11-07 896399/week @ 2025-11-14 695398/week @ 2025-11-21 575838/week @ 2025-11-28 937559/week @ 2025-12-05 870983/week @ 2025-12-12 473277/week @ 2025-12-19 278123/week @ 2025-12-26 709643/week @ 2026-01-02

2,503,353 downloads per month
Used in 2,014 crates (696 directly)

MIT/Apache

125KB
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.2–1.4MB
~29K SLoC