thisctx 0.3.0

Easily create error with contexts
Documentation

🎈 thisctx

A small crate works with thiserror to create errors with contexts, inspired by snafu.

✍️ Examples

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

#[derive(Debug, Error, WithContext)]
pub enum Error {
    #[error("I/O failed '{path}': {source}")]
    IoFaild {
        source: std::io::Error,
        path: PathBuf,
    },
}

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

📝 Todo

  • Switch to Rust 2021.
  • MSRV v1.33
  • Use derive macro instead.
  • Add attributes to context types.
  • Support transparent error.
  • Support generics.
  • Simplify the derive implementation.
  • More documentation.
  • More tests.

🚩 Minimal suppoted Rust version

All tests under tests/* passed with rustc v1.33, previous versions may not compile.

⚖️ License

Licensed under either of

at your option.