msg_channel_core/
handle.rs

1use std::future::Future;
2
3pub trait HandleReplay<M> {
4    type Replay: Send + 'static;
5    type MsgReplay: Into<Self::Replay>;
6}
7
8pub trait HandleSync<M>: Sync {
9    fn is_blocking(&self, _msg: &M) -> bool {
10        true
11    }
12    type Replay: Send + 'static;
13    fn handle(&mut self, msg: M) -> Self::Replay;
14}
15
16impl<T: Sync> HandleSync<()> for T {
17    type Replay = ();
18
19    fn handle(&mut self, _: ()) -> Self::Replay {}
20}
21
22pub trait HandleAsync<M> {
23    type Replay: Send + 'static;
24    fn handle(&mut self, msg: M) -> impl Future<Output = Self::Replay>;
25}
26
27impl<T> HandleAsync<()> for T {
28    type Replay = ();
29
30    async fn handle(&mut self, _: ()) -> Self::Replay {}
31}
32pub trait HandleAsyncConcurrent<M> {
33    type Replay: Send + 'static;
34    fn handle(&self, msg: M) -> impl Future<Output = Self::Replay>;
35}
36impl<T> HandleAsyncConcurrent<()> for T {
37    type Replay = ();
38
39    async fn handle(&self, _: ()) -> Self::Replay {}
40}
41pub trait HandleSyncConcurrent<M>: Sync {
42    fn is_blocking(&self, _msg: &M) -> bool {
43        true
44    }
45    type Replay: Send + 'static;
46    fn handle(&self, msg: M) -> Self::Replay;
47}
48impl<T: Sync> HandleSyncConcurrent<()> for T {
49    type Replay = ();
50
51    fn handle(&self, _: ()) -> Self::Replay {}
52}