Trait dptree::description::HandlerDescription
source · [−]pub trait HandlerDescription: Sized + Send + Sync + 'static {
Show 13 methods
fn entry() -> Self;
fn user_defined() -> Self;
fn merge_chain(&self, other: &Self) -> Self;
fn merge_branch(&self, other: &Self) -> Self;
fn map() -> Self { ... }
fn map_async() -> Self { ... }
fn filter() -> Self { ... }
fn filter_async() -> Self { ... }
fn filter_map() -> Self { ... }
fn filter_map_async() -> Self { ... }
fn inspect() -> Self { ... }
fn inspect_async() -> Self { ... }
fn endpoint() -> Self { ... }
}
Expand description
Handler description.
This trait allows information to flow “back up” the tree, allowing to check its structure.
Examples
Count how many branches are in the tree:
use dptree::{prelude::DependencyMap, Handler, HandlerDescription};
struct CountBranches(u32);
impl HandlerDescription for CountBranches {
fn entry() -> Self {
Self(0)
}
fn user_defined() -> Self {
Self(0)
}
fn merge_chain(&self, other: &Self) -> Self {
Self(self.0 + other.0)
}
fn merge_branch(&self, other: &Self) -> Self {
Self(self.0 + other.0 + 1)
}
}
#[track_caller]
fn assert_count(count: u32, handler: Handler<DependencyMap, (), CountBranches>) {
assert_eq!(handler.description().0, count);
}
assert_count(0, dptree::entry());
assert_count(1, dptree::entry().branch(dptree::entry()));
assert_count(
5,
dptree::entry()
.branch(
dptree::entry()
.branch(dptree::entry().branch(dptree::filter(|| true)))
.branch(dptree::entry().chain(dptree::filter(|| false))),
)
.branch(dptree::entry()),
);
Required Methods
fn user_defined() -> Self
fn user_defined() -> Self
Description for a user-defined handler that can do practically everything.
fn merge_chain(&self, other: &Self) -> Self
fn merge_chain(&self, other: &Self) -> Self
Merge descriptions to get a description for a chain handler.
fn merge_branch(&self, other: &Self) -> Self
fn merge_branch(&self, other: &Self) -> Self
Merge descriptions to get a description for a branch handler.
Provided Methods
Description for map_async
.
Default implementation
By default this returns the value from
user_defined
.
fn filter_async() -> Self
fn filter_async() -> Self
Description for filter_async
.
Default implementation
By default this returns the value from
user_defined
.
fn filter_map() -> Self
fn filter_map() -> Self
Description for filter_map
.
Default implementation
By default this returns the value from
user_defined
.
fn filter_map_async() -> Self
fn filter_map_async() -> Self
Description for filter_map_async
.
Default implementation
By default this returns the value from
user_defined
.
Description for inspect
.
Default implementation
By default this returns the value from
user_defined
.
fn inspect_async() -> Self
fn inspect_async() -> Self
Description for inspect_async
.
Default implementation
By default this returns the value from
user_defined
.
Description for endpoint
.
Default implementation
By default this returns the value from
user_defined
.