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
use crate::endpoint::{Endpoint};
use crate::engine::{AdapterLauncher};
use crate::driver::{AdapterEvent};
use crate::adapters::{
tcp::{TcpAdapter},
udp::{UdpAdapter},
web_socket::{WsAdapter},
};
use num_enum::IntoPrimitive;
use strum::{IntoEnumIterator, EnumIter};
#[derive(IntoPrimitive, EnumIter)]
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Transport {
Tcp,
Udp,
Ws,
}
impl Transport {
pub fn id(self) -> u8 {
self.into()
}
fn mount_adapter<C>(self, launcher: &mut AdapterLauncher<C>)
where C: Fn(Endpoint, AdapterEvent<'_>) + Send + 'static {
match self {
Transport::Tcp => launcher.mount(self.id(), TcpAdapter),
Transport::Udp => launcher.mount(self.id(), UdpAdapter),
Transport::Ws => launcher.mount(self.id(), WsAdapter),
};
}
pub(crate) fn mount_all<C>(launcher: &mut AdapterLauncher<C>)
where C: Fn(Endpoint, AdapterEvent<'_>) + Send + 'static {
Transport::iter().for_each(|transport| transport.mount_adapter(launcher));
}
}