28 releases

✓ Uses Rust 2018 edition

new 0.6.6 Apr 5, 2020
0.6.3 Mar 19, 2020
0.6.0 Nov 7, 2019
0.4.3 Jul 24, 2019
0.2.0 Mar 26, 2019

#7 in Rust patterns

Download history 6860/week @ 2019-12-17 4048/week @ 2019-12-24 4807/week @ 2019-12-31 10406/week @ 2020-01-07 7721/week @ 2020-01-14 10622/week @ 2020-01-21 8458/week @ 2020-01-28 6839/week @ 2020-02-04 5783/week @ 2020-02-11 6061/week @ 2020-02-18 5865/week @ 2020-02-25 6474/week @ 2020-03-03 7262/week @ 2020-03-10 8013/week @ 2020-03-17 7459/week @ 2020-03-24 8283/week @ 2020-03-31

32,672 downloads per month
Used in 137 crates (116 directly)

MIT/Apache

56KB
993 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.5–0.8MB
~19K SLoC