pub enum ErrorTree<L, E> {
Leaf(E),
Edge(L, Box<ErrorTree<L, E>>),
Vec(Vec<ErrorTree<L, E>>),
}
Expand description
The error Tree structure.
L
is the Label type.E
is the inner Error type. It can be an error enum (from the thiserror package).
Variants§
Leaf(E)
Stores your single error type.
Edge(L, Box<ErrorTree<L, E>>)
Adds a label to the subtree.
Vec(Vec<ErrorTree<L, E>>)
Groups multiple subtrees at the same level.
Implementations§
Source§impl<L, E> ErrorTree<L, E>where
L: Clone,
impl<L, E> ErrorTree<L, E>where
L: Clone,
Sourcepub fn flatten_tree(self) -> Vec<FlatError<L, E>>
pub fn flatten_tree(self) -> Vec<FlatError<L, E>>
Flattens the error tree in a Vec
of FlatError
s.
#[derive(Debug)]
struct Error(String);
let error_1 = ErrorTree::leaf(Error("error1".into())).with_label("label1");
let error_2 = ErrorTree::leaf(Error("error2".into())).with_label("label2");
let errors = vec![error_1, error_2];
let tree: ErrorTree<&'static str, Error> = errors.into();
let tree = tree.with_label("parent_label");
let flat_errors = tree.flatten_tree();
assert!(
matches!(
&flat_errors[..],
[
FlatError {
path: path1,
error: Error(error1),
},
FlatError {
path: path2,
error: Error(error2),
},
]
if path1 == &vec!["label1", "parent_label"]
&& path2 == &vec!["label2", "parent_label"]
&& error1 == "error1"
&& error2 == "error2"
),
"unexpected: {:#?}",
flat_errors
);
Trait Implementations§
Source§impl<L, E> IntoErrorTree<L, E> for ErrorTree<L, E>
impl<L, E> IntoErrorTree<L, E> for ErrorTree<L, E>
Source§fn with_label(self, label: L) -> ErrorTree<L, E>
fn with_label(self, label: L) -> ErrorTree<L, E>
Adds a
label
to an error tree. Read moreAuto Trait Implementations§
impl<L, E> Freeze for ErrorTree<L, E>
impl<L, E> RefUnwindSafe for ErrorTree<L, E>where
E: RefUnwindSafe,
L: RefUnwindSafe,
impl<L, E> Send for ErrorTree<L, E>
impl<L, E> Sync for ErrorTree<L, E>
impl<L, E> Unpin for ErrorTree<L, E>
impl<L, E> UnwindSafe for ErrorTree<L, E>where
E: UnwindSafe,
L: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more