mediator_sys/mediator/synchronous/basic/
interface.rs

1use std::{fmt::Debug, sync::mpsc::TryRecvError};
2
3use crate::mediator::listener::Listener;
4
5/// Publish an event `Ev` from within a handler.
6pub trait SyncMediatorInternal<Ev: Debug> {
7    fn publish(&self, event: Ev);
8}
9
10/// Send a request `Req` for processing to the mediator.
11/// This will call the handler.
12pub trait SyncMediatorInternalHandle<Ev: Debug> {
13    fn send<Req>(&self, req: Req)
14    where
15        Self: RequestHandler<Req, Ev>;
16}
17
18/// Process the next event `Ev` from the channel.
19/// This will call all listeners with a clone of that event.
20pub trait SyncMediatorInternalNext {
21    fn next(&self) -> Result<(), TryRecvError>;
22}
23
24/// Handles the request `Req`.
25/// Implemented by the user.
26pub trait RequestHandler<Req, Res> {
27    fn handle(&self, req: Req);
28}
29
30/// Basic builder fuctionality:
31/// Adding a [`Listener`] to the builder.
32pub trait BasicMediatorBuilderInterface<M, Ev> {
33    fn add_listener<F>(self, f: F) -> Self
34    where
35        F: Listener<Ev>,
36        Ev: Debug;
37}