eyre/src/fmt.rs
Jane Lusby 6b601f8215
Propogate context to the top most error when wrapping inner errors (#5)
* Propogate context when wrapping errors with Option::take

* fix test failure in fmt output

* bump version for release
2020-04-07 14:26:48 -07:00

23 lines
631 B
Rust

use crate::error::ErrorImpl;
use crate::EyreContext;
use core::fmt;
impl<C> ErrorImpl<(), C>
where
C: EyreContext,
{
pub(crate) fn display(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.context
.as_ref()
.map(|context| context.display(self.error(), f))
.unwrap_or_else(|| std::fmt::Display::fmt(self.error(), f))
}
pub(crate) fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.context
.as_ref()
.map(|context| context.debug(self.error(), f))
.unwrap_or_else(|| std::fmt::Debug::fmt(self.error(), f))
}
}