1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use async_trait::async_trait;
use std::fmt::Debug;

/// Send a request `Req` asynchronously for processing to the mediator.
/// This will call the handler.
/// The handler here is context-dependent.
#[async_trait]
pub trait CxAwareAsyncMediatorInternalHandle<Dep, Ev: Debug> {
    async fn send<Req>(&self, req: Req)
    where
        Req: Send,
        Self: CxAwareAsyncRequestHandler<Dep, Req, Ev>;
}

/// Handles the request `Req` asynchronously.
/// Implemented by the user.
/// Gives access to the dependency `Dep`.
#[async_trait]
pub trait CxAwareAsyncRequestHandler<Dep, Req, Res> {
    async fn handle(&self, req: Req, dep: &Dep);
}

/// Advanced builder fuctionality:
/// Adding a dependency `dep` to the builder.
pub trait CxAwareMediatorBuilderInterface<M, Dep, Ev> {
    fn add_dependency(self, dep: Dep) -> Self
    where
        Ev: Debug;
}