22 releases (5 breaking)

✓ Uses Rust 2018 edition

0.6.0 Nov 7, 2019
0.4.4 Aug 7, 2019
0.4.3 Jul 24, 2019
0.2.0 Mar 26, 2019

#17 in Rust patterns

Download history 1301/week @ 2019-07-25 1381/week @ 2019-08-01 1667/week @ 2019-08-08 1599/week @ 2019-08-15 2464/week @ 2019-08-22 2146/week @ 2019-08-29 3649/week @ 2019-09-05 4862/week @ 2019-09-12 3471/week @ 2019-09-19 3413/week @ 2019-09-26 3641/week @ 2019-10-03 3170/week @ 2019-10-10 2987/week @ 2019-10-17 3720/week @ 2019-10-24 3874/week @ 2019-10-31

13,519 downloads per month
Used in 83 crates (75 directly)

MIT/Apache

56KB
983 lines

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::{ResultExt, Snafu};
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(ReadConfiguration { path })?;
    let path = unpack_config(&configuration);
    fs::write(&path, b"My complex calculation").context(WriteResult { 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.6–1MB
~21K SLoC