34 releases

0.7.0-beta.1 Oct 7, 2021
0.7.0-beta.0 Jul 5, 2021
0.6.10 Dec 3, 2020
0.6.9 Sep 22, 2020
0.2.0 Mar 26, 2019

#21 in Rust patterns

Download history 30251/week @ 2021-07-03 27857/week @ 2021-07-10 32119/week @ 2021-07-17 29004/week @ 2021-07-24 34404/week @ 2021-07-31 30671/week @ 2021-08-07 32030/week @ 2021-08-14 34367/week @ 2021-08-21 33552/week @ 2021-08-28 33501/week @ 2021-09-04 39750/week @ 2021-09-11 36703/week @ 2021-09-18 40563/week @ 2021-09-25 37291/week @ 2021-10-02 35473/week @ 2021-10-09 38618/week @ 2021-10-16

144,661 downloads per month
Used in 334 crates (208 directly)

MIT/Apache

185KB
4K 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(), source))]
    ReadConfiguration { source: io::Error, path: PathBuf },

    #[snafu(display("Unable to write result to {}: {}", path.display(), source))]
    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.3–1.3MB
~29K SLoC