Function type_check

Source
pub fn type_check(
    sig: &HandlerSignature,
    container: &DependencyMap,
    assumptions: &[Type],
)
Expand description

Performs run-time type checking.

If you are using DependencyMap, you should call this function before executing the handler via Handler::execute or Handler::dispatch. If you do not call this function before execution, type checking will be delayed until the actual execution, which can make things harder to debug.

sig can be obtained from Handler::sig. assumptions are added to the types of values from container.

§Panics

If container does not contain all the types that the handler accepts; in this case, helpful diagnostic information about missing types and code locations is displayed.

§Examples

use dptree::prelude::*;

#[derive(Clone)]
struct A;
#[derive(Clone)]
struct B;

// Requires both `A` and `B` to be present in the container.
let handler: Handler<()> = dptree::entry().filter(|_: A| true).endpoint(|_: B| async { () });

// Ok.
dptree::type_check(handler.sig(), &dptree::deps![A, B], &[]);

// Panics with a proper message.
dptree::type_check(handler.sig(), &dptree::deps![A /* Missing `B` */], &[]);