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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::{
error::{AlreadyLinkedError, TakeChannelError, TakeResourceError},
Channel, Storage,
};
use std::fmt::{Debug, Display};
pub trait Message<Bus>: Debug {
type Channel: Channel;
}
pub trait Resource<Bus>: Storage + Debug + Send {}
pub trait Bus: Default + Debug + Sized {
fn capacity<Msg>(&self, capacity: usize) -> Result<(), AlreadyLinkedError>
where
Msg: Message<Self> + 'static;
fn rx<Msg>(&self) -> Result<<Msg::Channel as Channel>::Rx, TakeChannelError>
where
Msg: Message<Self> + 'static;
fn tx<Msg>(&self) -> Result<<Msg::Channel as Channel>::Tx, TakeChannelError>
where
Msg: Message<Self> + 'static;
fn resource<Res>(&self) -> Result<Res, TakeResourceError>
where
Res: Resource<Self>;
}
#[derive(Debug)]
pub enum Link {
Tx,
Rx,
Both,
}
impl Display for Link {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Link::Tx => f.write_str("Tx"),
Link::Rx => f.write_str("Rx"),
Link::Both => f.write_str("Both"),
}
}
}