rd_std/builtin/
alias.rs

1use futures::future::BoxFuture;
2use rd_interface::{
3    registry::{EmptyConfig, NetFactory},
4    util::get_one_net,
5    Address, Context, INet, Result, TcpListener, TcpStream, UdpSocket,
6};
7
8pub struct AliasNet(rd_interface::Net);
9
10impl AliasNet {
11    fn new(net: rd_interface::Net) -> AliasNet {
12        AliasNet(net)
13    }
14}
15
16impl INet for AliasNet {
17    #[inline(always)]
18    fn tcp_connect<'life0: 'a, 'life1: 'a, 'a>(
19        &'life0 self,
20        ctx: &'life1 mut Context,
21        addr: Address,
22    ) -> BoxFuture<'a, Result<TcpStream>>
23    where
24        Self: 'a,
25    {
26        self.0.tcp_connect(ctx, addr)
27    }
28
29    #[inline(always)]
30    fn tcp_bind<'life0: 'a, 'life1: 'a, 'a>(
31        &'life0 self,
32        ctx: &'life1 mut Context,
33        addr: Address,
34    ) -> BoxFuture<'a, Result<TcpListener>>
35    where
36        Self: 'a,
37    {
38        self.0.tcp_bind(ctx, addr)
39    }
40
41    #[inline(always)]
42    fn udp_bind<'life0: 'a, 'life1: 'a, 'a>(
43        &'life0 self,
44        ctx: &'life1 mut Context,
45        addr: Address,
46    ) -> BoxFuture<'a, Result<UdpSocket>>
47    where
48        Self: 'a,
49    {
50        self.0.udp_bind(ctx, addr)
51    }
52}
53
54impl NetFactory for AliasNet {
55    const NAME: &'static str = "alias";
56    type Config = EmptyConfig;
57    type Net = Self;
58
59    fn new(nets: Vec<rd_interface::Net>, _config: Self::Config) -> Result<Self> {
60        Ok(AliasNet::new(get_one_net(nets)?))
61    }
62}