32 releases

0.6.10 Dec 3, 2020
0.6.9 Sep 22, 2020
0.6.8 May 12, 2020
0.6.3 Mar 19, 2020
0.2.0 Mar 26, 2019

#31 in Rust patterns

Download history 18982/week @ 2020-09-25 14870/week @ 2020-10-02 14080/week @ 2020-10-09 12558/week @ 2020-10-16 13731/week @ 2020-10-23 13752/week @ 2020-10-30 14075/week @ 2020-11-06 16498/week @ 2020-11-13 18262/week @ 2020-11-20 16471/week @ 2020-11-27 18597/week @ 2020-12-04 16427/week @ 2020-12-11 16868/week @ 2020-12-18 11445/week @ 2020-12-25 17036/week @ 2021-01-01 21208/week @ 2021-01-08

65,753 downloads per month
Used in 247 crates (158 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