40 releases

0.7.3 Oct 20, 2022
0.7.1 May 3, 2022
0.7.0 Jan 4, 2022
0.7.0-beta.2 Nov 15, 2021
0.2.0 Mar 26, 2019

#221 in Procedural macros

Download history 61008/week @ 2022-08-18 64126/week @ 2022-08-25 60957/week @ 2022-09-01 61311/week @ 2022-09-08 65676/week @ 2022-09-15 57766/week @ 2022-09-22 52744/week @ 2022-09-29 59912/week @ 2022-10-06 55456/week @ 2022-10-13 63579/week @ 2022-10-20 62278/week @ 2022-10-27 69243/week @ 2022-11-03 70062/week @ 2022-11-10 67154/week @ 2022-11-17 63403/week @ 2022-11-24 69719/week @ 2022-12-01

282,970 downloads per month
Used in 529 crates (2 directly)

MIT/Apache

135KB
3.5K 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

~230–640KB
~15K SLoC