1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! # Anywrap
//! Anywrap is an error handler designed for applications, similar to anyhow, but it supports matching on enum variants, making it more ergonomic.
//! # Example
//!
//! ```rust
//! 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:?}");
//! }
//! }
//! ```
pub use ;