Skip to main content

HandlerDescription

Trait HandlerDescription 

Source
pub trait HandlerDescription:
    Sized
    + MaybeSend
    + MaybeSync
    + 'static {
Show 19 methods // Required methods fn entry() -> Self; fn user_defined() -> Self; fn merge_chain(&self, other: &Self) -> Self; fn merge_branch(&self, other: &Self) -> Self; // Provided methods 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 { ... } fn try_filter() -> Self { ... } fn try_filter_async() -> Self { ... } fn try_filter_map() -> Self { ... } fn try_filter_map_async() -> Self { ... } fn try_map() -> Self { ... } fn try_map_async() -> Self { ... }
}
Expand description

Handler description.

This trait allows information to flow “back up” the tree, allowing a user 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<(), CountBranches>) {
    assert_eq!(handler.description().0, count);
}

assert_count(0, dptree::entry());
assert_count(1, dptree::entry().branch(dptree::inspect(|| ())));
assert_count(
    5,
    dptree::entry()
        .branch(
            dptree::entry()
                .branch(dptree::entry().branch(dptree::filter(|| true)))
                .branch(dptree::entry().chain(dptree::filter(|| false))),
        )
        .branch(dptree::inspect(|| ())),
);

Required Methods§

Source

fn entry() -> Self

Description for entry.

Source

fn user_defined() -> Self

Description for a user-defined handler that can do practically everything.

Source

fn merge_chain(&self, other: &Self) -> Self

Merge descriptions to get a description for a chain handler.

Source

fn merge_branch(&self, other: &Self) -> Self

Merge descriptions to get a description for a branch handler.

Provided Methods§

Source

fn map() -> Self

Description for map.

§Default implementation

By default this returns the value from user_defined.

Source

fn map_async() -> Self

Description for map_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn filter() -> Self

Description for filter.

§Default implementation

By default this returns the value from user_defined.

Source

fn filter_async() -> Self

Description for filter_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn filter_map() -> Self

Description for filter_map.

§Default implementation

By default this returns the value from user_defined.

Source

fn filter_map_async() -> Self

Description for filter_map_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn inspect() -> Self

Description for inspect.

§Default implementation

By default this returns the value from user_defined.

Source

fn inspect_async() -> Self

Description for inspect_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn endpoint() -> Self

Description for endpoint.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_filter() -> Self

Description for try_filter.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_filter_async() -> Self

Description for try_filter_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_filter_map() -> Self

Description for try_filter_map.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_filter_map_async() -> Self

Description for try_filter_map_async.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_map() -> Self

Description for try_map.

§Default implementation

By default this returns the value from user_defined.

Source

fn try_map_async() -> Self

Description for try_map_async.

§Default implementation

By default this returns the value from user_defined.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl HandlerDescription for Unspecified

Source§

impl<T, S> HandlerDescription for InterestSet<T, S>
where T: EventKind<S> + Eq + Hash + Clone + Send + Sync + 'static, S: BuildHasher + Clone + Send + Sync + 'static,