flex_error/tracer_impl/
anyhow.rs1use crate::tracer::{ErrorMessageTracer, ErrorTracer};
2use core::fmt::{Debug, Display};
3
4pub type AnyhowTracer = anyhow::Error;
6
7impl ErrorMessageTracer for AnyhowTracer {
8 fn new_message<E: Display>(err: &E) -> Self {
9 let message = alloc::format!("{}", err);
10 AnyhowTracer::msg(message)
11 }
12
13 fn add_message<E: Display>(self, err: &E) -> Self {
14 let message = alloc::format!("{}", err);
15 self.context(message)
16 }
17
18 #[cfg(feature = "std")]
19 fn as_error(&self) -> Option<&(dyn std::error::Error + 'static)> {
20 use core::ops::Deref;
21 Some(self.deref())
22 }
23}
24
25impl<E> ErrorTracer<E> for AnyhowTracer
26where
27 E: Display + Debug + Send + Sync + 'static,
28{
29 fn new_trace(err: E) -> Self {
30 AnyhowTracer::msg(err)
31 }
32
33 fn add_trace(self, err: E) -> Self {
34 let message = alloc::format!("{}", err);
35 self.context(message)
36 }
37}