31 releases

0.6.9 Sep 22, 2020
0.6.8 May 12, 2020
0.6.6 Apr 5, 2020
0.6.3 Mar 19, 2020
0.2.0 Mar 26, 2019

#10 in Rust patterns

Download history 14648/week @ 2020-06-09 14278/week @ 2020-06-16 13328/week @ 2020-06-23 9786/week @ 2020-06-30 15663/week @ 2020-07-07 13488/week @ 2020-07-14 12724/week @ 2020-07-21 19103/week @ 2020-07-28 16034/week @ 2020-08-04 13448/week @ 2020-08-11 13858/week @ 2020-08-18 15214/week @ 2020-08-25 14394/week @ 2020-09-01 16963/week @ 2020-09-08 14689/week @ 2020-09-15 15720/week @ 2020-09-22

62,162 downloads per month
Used in 213 crates (153 directly)

MIT/Apache

64KB
1K 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::{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.4–1MB
~22K SLoC