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

#8 in #domain-specific

Download history 915046/week @ 2025-08-11 804705/week @ 2025-08-18 764267/week @ 2025-08-25 710454/week @ 2025-09-01 758098/week @ 2025-09-08 754127/week @ 2025-09-15 779517/week @ 2025-09-22 801670/week @ 2025-09-29 802280/week @ 2025-10-06 769655/week @ 2025-10-13 732431/week @ 2025-10-20 824611/week @ 2025-10-27 850239/week @ 2025-11-03 803168/week @ 2025-11-10 952615/week @ 2025-11-17 497709/week @ 2025-11-24

3,130,924 downloads per month
Used in 1,930 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

~190–610KB
~14K SLoC