pub struct ErrTree<'a> { /* private fields */ }
Expand description
Intermediate struct for printing created by AsErrTree
.
Only allowing construction through Self::with_pkg
and Self::no_pkg
allows arbitrary combinations of metadata tracking without changing
construction syntax. Sources are stored under three layers of indirection
to allow for maximum type and size flexibility without generics or heap
allocation.
See tree
to reduce Self::with_pkg
boilerplate.
§Manual Implementation Example
use bare_err_tree::{ErrTree, ErrTreePkg, AsErrTree, ErrTreeConv};
#[derive(Debug)]
pub struct HighLevelIo {
source: std::io::Error,
_pkg: ErrTreePkg,
}
impl HighLevelIo {
#[track_caller]
pub fn new(source: std::io::Error) -> Self {
Self {
source,
_pkg: ErrTreePkg::new(),
}
}
}
impl AsErrTree for HighLevelIo {
fn as_err_tree(&self, func: &mut dyn FnMut(ErrTree<'_>)) {
// Cast to ErrTree adapter via Error
let source = ErrTreeConv::from(&self.source as &dyn Error);
// Convert to a single item iterator
let source_iter = &mut core::iter::once(source);
// Call the formatting function
(func)(ErrTree::with_pkg(self, source_iter, &self._pkg));
}
}
impl Error for HighLevelIo {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.source)
}
}
impl Display for HighLevelIo {
...
}
Implementations§
Source§impl<'a> ErrTree<'a>
impl<'a> ErrTree<'a>
Sourcepub fn with_pkg(
inner: &'a dyn Error,
sources: &'a mut dyn Iterator<Item = ErrTreeConv<'a>>,
pkg: &'a ErrTreePkg,
) -> Self
pub fn with_pkg( inner: &'a dyn Error, sources: &'a mut dyn Iterator<Item = ErrTreeConv<'a>>, pkg: &'a ErrTreePkg, ) -> Self
Common constructor, with metadata.
Sourcepub fn no_pkg(
inner: &'a dyn Error,
sources: &'a mut dyn Iterator<Item = ErrTreeConv<'a>>,
) -> Self
pub fn no_pkg( inner: &'a dyn Error, sources: &'a mut dyn Iterator<Item = ErrTreeConv<'a>>, ) -> Self
Constructor for when metadata needs to be hidden.
Sourcepub fn sources(self) -> impl Iterator<Item = ErrTreeConv<'a>>
pub fn sources(self) -> impl Iterator<Item = ErrTreeConv<'a>>
Consumes this tree to return its sources
Auto Trait Implementations§
impl<'a> Freeze for ErrTree<'a>
impl<'a> !RefUnwindSafe for ErrTree<'a>
impl<'a> !Send for ErrTree<'a>
impl<'a> !Sync for ErrTree<'a>
impl<'a> Unpin for ErrTree<'a>
impl<'a> !UnwindSafe for ErrTree<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more