Small changes

This commit is contained in:
Michael Pfaff 2024-03-20 23:15:16 -04:00
parent 8517408765
commit fb08be31d4
4 changed files with 24 additions and 4 deletions

View File

@ -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"]

View File

@ -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<E> 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<T, E> Explain for Result<T, E>
where
E: std::error::Error + 'static,

View File

@ -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<HowInner>);
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(())

View File

@ -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(())
}