diff --git a/Cargo.toml b/Cargo.toml index 1b28949..57b466e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,9 @@ termination = ["dep:ansee"] ansee = { git = "https://git.pfaff.dev/michael/ansee", optional = true } typeid-cast = "0.1" +[dev-dependencies] +how = { path = ".", features = ["termination"] } + [[example]] name = "output" -required-features = [ "termination" ] +required-features = ["termination"] diff --git a/src/explain.rs b/src/explain.rs index 83d6d7e..ee1e17e 100644 --- a/src/explain.rs +++ b/src/explain.rs @@ -1,7 +1,7 @@ use std::panic::Location; use std::sync::Arc; -use crate::{How, IntoContext, Detail}; +use crate::{Detail, How, IntoContext}; pub trait Explain: Sized { type Output; @@ -40,6 +40,19 @@ impl Explain for How { } } +/*impl Explain for E +where + E: std::error::Error, +{ + type Output = How; + + #[inline(always)] + #[track_caller] + fn context(self, context: impl IntoContext) -> Self::Output { + How::new(self.to_string()).context(context) + } +}*/ + impl Explain for Result where E: std::error::Error + 'static, diff --git a/src/how.rs b/src/how.rs index f6dbaa0..c203a9e 100644 --- a/src/how.rs +++ b/src/how.rs @@ -9,7 +9,10 @@ use crate::report::report_write; /// By default, does not implement [`Clone`] because [`std::backtrace::Backtrace`] does not /// implement [`Clone`]. However, the `clone-with-caveats` feature may be used to enable a /// [`Clone`] impl that sets the cloned `backtrace` to [`std::backtrace::Backtrace::disabled`]. -#[cfg_attr(any(feature = "arc-backtrace", feature = "clone-with-caveats"), derive(Clone))] +#[cfg_attr( + any(feature = "arc-backtrace", feature = "clone-with-caveats"), + derive(Clone) +)] pub struct How(Box); struct HowInner { @@ -145,6 +148,7 @@ impl std::fmt::Display for How { if i != 0 { f.write_str("\n")?; } + report_write!(f, &opts.indent().next(), "{ctx}")?; } Ok(()) diff --git a/src/report.rs b/src/report.rs index 010336d..fff3c20 100644 --- a/src/report.rs +++ b/src/report.rs @@ -41,7 +41,7 @@ pub(crate) use report_write; #[inline] fn write_indent(n: usize, f: &mut impl Write) -> std::fmt::Result { for _ in 0..n { - f.write_str(" ")?; + f.write_str(" ")?; } Ok(()) }