anywrap 0.1.0

Anywrap is an error handling mechanism with pseudo-stack traces implemented through SNAFU, the proc macro trace_error, and the DebugTrace trait, inspired by GreptimeDB.
Documentation
  • Coverage
  • 71.43%
    5 out of 7 items documented1 out of 3 items with examples
  • Size
  • Source code size: 6.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 418.68 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dancingpeanut/snafu-tracing
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dancingpeanut
anywrap-0.1.0 has been yanked.

Anywrap

Anywrap is an error handler designed for applications, similar to anyhow, but it supports matching on enum variants, making it more ergonomic.

Example

use std::fmt;
use std::fs::File;
use anywrap::{anywrap, AnyWrap};

pub struct ErrorCode(pub u32);

impl fmt::Display for ErrorCode {
   fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
      write!(f, "{}", self.0)
   }
}

#[derive(AnyWrap)]
#[anywrap]
pub enum Error {
   #[anywrap_attr(display = "Error Code: {code}", from = "code")]
   Code { code: ErrorCode },
   #[anywrap_attr(display = "{source}")]
   IO { source: std::io::Error },
}

pub type Result<T, E = Error> = std::result::Result<T, E>;

pub fn define_error() -> Result<()> {
   let e = Error::from(ErrorCode(1));
   Err(e)
}

pub fn chain1() -> Result<()> {
   define_error().context("chain1")
}

pub fn with_chain() -> Result<()> {
   chain1().context("with_chain")
}

pub fn auto() -> Result<()> {
   let _ = File::open("test.txt")?;

   Ok(())
}

fn main() {
   if let Err(e) = auto() {
      println!("--12: {e:?}");
   }
   if let Err(e) = with_chain() {
      println!("--15 display: {e}");
      println!("--15 debug: {e:?}");
   }
}

Or refer to: full example