thisctx 0.1.0

Easily create error with contexts
Documentation

THISCTX

A simple crate work with thiserror to create errors with contexts, inspired by snafu.

Examples

use std::fs;
use std::path::{Path, PathBuf};
use thisctx::{thisctx, ResultExt};
use thiserror::Error;

thisctx! {
    #[derive(Debug, Error)]
    pub enum Error {
        #[error("I/O failed '{}': {src}", .ctx.0.display())]
        IoFaild {
            #[source]
            @source
            src: std::io::Error,
            @context
            ctx:
                #[derive(Debug)]
                struct (PathBuf),
        },
    }
}

fn load_config(path: &Path) -> Result<String, Error> {
    fs::read_to_string(path).context(IoFaild(path))
}

License

This software is released under the MIT License.