• Stars
    star
    1,378
  • Rank 34,130 (Top 0.7 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily assign underlying errors into domain-specific errors while adding context

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.

More Repositories

1

rust-ffi-omnibus

A collection of examples of using code written in Rust from other languages
SCSS
472
star
2

twox-hash

A Rust implementation of the XXHash algorithm.
Rust
345
star
3

sxd-document

An XML library in Rust
Rust
147
star
4

jetscii

A tiny library to efficiently search strings for sets of ASCII characters and byte slices for sets of bytes.
Rust
113
star
5

sxd-xpath

An XPath library in Rust
Rust
111
star
6

rust-arduino-blink-led-no-core-with-cargo

Blink the LED on the Arduino Uno with Rust and Cargo
Rust
72
star
7

rust-arduino-blink-led-no-core

Blink the LED on the Arduino Uno with Rust
Rust
46
star
8

nginx-template-image

Allow Docker environment variables in nginx configuration files
Shell
39
star
9

cupid

Get information about the x86 and x86_64 processor
Rust
34
star
10

ebene-rust

A Rust source code parser and explorer
TypeScript
22
star
11

peresil

A simplistic parsing library in Rust
Rust
20
star
12

mini-crater

Rust
19
star
13

rspec-search-and-destroy

Automatically finds test-ordering bugs in RSpec test suites
Ruby
18
star
14

rust-mre

A collection of techniques to reduce Rust code in order to get better help
17
star
15

temporal-coupling

Explores git repositories to find files that are commonly changed together
Ruby
12
star
16

advent-of-code-2021

Rust
7
star
17

human-resource-machine

A little toy to parse Human Resource Machine save files and then replay them.
Rust
7
star
18

fuzzy-pickles

A Rust parser to power Strata Rust
Rust
7
star
19

ebene

Rust
5
star
20

providence

Rust
5
star
21

clojure-ruby

An extremely bare-bones Ruby interpreter
Clojure
5
star
22

advent-of-code-2022

Rust
5
star
23

stack-overflow-relay

Rust
4
star
24

java-dependency-graph

Ruby
4
star
25

simavr

An AVR simulator / emulator
Rust
4
star
26

sxd

Rust
4
star
27

sxd-string-slab

A string interning pool tailored for XML documents
Rust
3
star
28

snafu-lints

Optional lints for SNAFU
Rust
3
star
29

jasmine-junitreporter-gem

A gem wrapping jasmine-junitreporter for the Rails Asset Pipeline
Ruby
3
star
30

advent-of-code-2019

Rust
3
star
31

fantastic-rotary

Rust
2
star
32

ruby-brainfuck

An extremely bare-bones Brainfuck interpreter
Ruby
2
star
33

advent-of-code-2023

Rust
1
star
34

rust-charge

Rust
1
star
35

advent-of-code-2020

Rust
1
star
36

snafu-upgrade-assistant

Rust
1
star
37

advent-of-code-2016

My Rust solutions for http://adventofcode.com/2016
Rust
1
star
38

shepmaster.github.com

My blog
HTML
1
star
39

jasmine-junitreporter

A Jasmine 2 reporter that outputs JUnit 4.x compatible results when used with PhantomJS.
JavaScript
1
star
40

actions-scratch

Rust
1
star
41

stack-overflow-comments

My boilerplate comments
1
star
42

diesel-join-to-subquery

An example of working around joining to a subquery with Diesel
Rust
1
star
43

typescript-css-modules-theme

An example of using CSS modules with themes in TypeScript and React 16.3
TypeScript
1
star
44

sxd-cpp

C++ XML Library
C++
1
star
45

crispy-sniffle

Rust
1
star