52 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

#12 in #domain-specific

Download history 796748/week @ 2025-10-30 805568/week @ 2025-11-06 887784/week @ 2025-11-13 798890/week @ 2025-11-20 513617/week @ 2025-11-27 901418/week @ 2025-12-04 857133/week @ 2025-12-11 625384/week @ 2025-12-18 276359/week @ 2025-12-25 584315/week @ 2026-01-01 1024844/week @ 2026-01-08 1041565/week @ 2026-01-15 1240594/week @ 2026-01-22 1165210/week @ 2026-01-29 993536/week @ 2026-02-05 768421/week @ 2026-02-12

4,395,550 downloads per month
Used in 2,261 crates (2 directly)

MIT/Apache

140KB
3.5K 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

~150–550KB
~13K SLoC