snafu_tracing/
lib.rs

1//! Snafu tracing
2//!
3
4//! # Example
5//!
6//! ```rust
7//! use snafu::Snafu;
8//! use snafu_tracing::{DebugTrace, trace_error, quick_tracing};
9//! 
10//! pub type Result<T, E = Error> = std::result::Result<T, E>;
11//! 
12//! #[trace_error]
13//! #[derive(Snafu, DebugTrace)]
14//! #[snafu(module, context(suffix(false)), visibility(pub))]
15//! pub enum Error {
16//!     #[snafu(display("{_error}"))]
17//!     Any { _error: String },
18//!     #[snafu(display("{error_source}"))]
19//!     Wrap {
20//!         #[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, |e| e)))]
21//!         error_source: Box<dyn std::error::Error + Send + Sync>,
22//!     },
23//! }
24//! 
25//! quick_tracing!(anyerr, crate::error::Any);
26//! 
27//! pub fn hello_err() -> Result<()> {
28//!     let _e = anyerr!("Any error test! {}", 123);
29//!     Err(anyerr!("Any error test!"))
30//! }
31//! 
32//! fn main() {
33//!     let e = hello_err();
34//!     println!("{:?}", e);
35//! }
36//! ```
37
38use std::error::Error;
39use std::fmt;
40
41pub use snafu_tracing_macro::{DebugTrace, quick_tracing, trace_error};
42
43pub trait DebugTrace: Error {
44    fn debug_trace(&self, f: &mut fmt::Formatter) -> Result<u32, fmt::Error>;
45}
46
47impl Error for Box<dyn DebugTrace + Send + Sync + 'static> {
48    fn source(&self) -> Option<&(dyn Error + 'static)> {
49        Error::source(Box::as_ref(self))
50    }
51}