fut_compat/net/
async_std.rs1use super::*;
2
3use ::async_std::net;
4
5
6
7#[async_trait]
8impl TcpStream for net::TcpStream {
9 async fn connect<A: ToSocketAddrs + Send>(addrs: A) -> std::io::Result<Self> {
10 let addrs: Vec<SocketAddr> = ToSocketAddrs::to_socket_addrs(addrs).await.collect();
11
12 Self::connect(&addrs[..]).await
13 }
14
15 async fn peek(&self, buf: &mut [u8]) -> std::io::Result<usize> {
16 self.peek(buf).await
17 }
18
19 fn peer_addr(&self) -> std::io::Result<SocketAddr> {
20 self.peer_addr()
21 }
22
23 fn local_addr(&self) -> std::io::Result<SocketAddr> {
24 self.local_addr()
25 }
26
27 fn nodelay(&self) -> std::io::Result<bool> {
28 self.nodelay()
29 }
30
31 fn set_nodelay(&self, nodelay: bool) -> std::io::Result<()> {
32 self.set_nodelay(nodelay)
33 }
34
35 fn ttl(&self) -> std::io::Result<u32> {
36 self.ttl()
37 }
38
39 fn set_ttl(&self, ttl: u32) -> std::io::Result<()> {
40 self.set_ttl(ttl)
41 }
42}
43
44
45
46#[async_trait]
47impl TcpListener for net::TcpListener {
48 type TcpStream = net::TcpStream;
49
50 async fn bind<A: ToSocketAddrs + Send>(addrs: A) -> std::io::Result<Self> {
51 let addrs: Vec<SocketAddr> = ToSocketAddrs::to_socket_addrs(addrs).await.collect();
52
53 Self::bind(&addrs[..]).await
54 }
55
56 async fn accept(&self) -> std::io::Result<(Self::TcpStream, SocketAddr)> {
57 self.accept().await
58 }
59
60 fn local_addr(&self) -> std::io::Result<SocketAddr> {
61 self.local_addr()
62 }
63}
64
65
66
67#[cfg(unix)]
68#[cfg_attr(docsrs, doc(cfg(unix)))]
69#[async_trait]
70impl UnixStream for ::async_std::os::unix::net::UnixStream {
71 type SocketAddr = std::os::unix::net::SocketAddr;
72
73 async fn connect<P: AsRef<Path> + Send>(path: P) -> std::io::Result<Self> {
74 let path = path.as_ref();
75 let path: &Path = path.into();
76
77 Self::connect(path).await
78 }
79
80 fn pair() -> std::io::Result<(Self, Self)> {
81 Self::pair()
82 }
83
84 fn peer_addr(&self) -> std::io::Result<Self::SocketAddr> {
85 self.peer_addr()
86 }
87
88 fn local_addr(&self) -> std::io::Result<Self::SocketAddr> {
89 self.local_addr()
90 }
91}
92
93
94
95#[cfg(unix)]
96#[cfg_attr(docsrs, doc(cfg(unix)))]
97#[async_trait]
98impl UnixListener for ::async_std::os::unix::net::UnixListener {
99 type UnixStream = ::async_std::os::unix::net::UnixStream;
100 type SocketAddr = std::os::unix::net::SocketAddr;
101
102 async fn bind<P: AsRef<Path> + Send>(path: P) -> std::io::Result<Self> {
103 let path = path.as_ref();
104 let path: &Path = path.into();
105
106 Self::bind(path).await
107 }
108
109 async fn accept(&self) -> std::io::Result<(Self::UnixStream, Self::SocketAddr)> {
110 self.accept().await
111 }
112
113 fn local_addr(&self) -> std::io::Result<Self::SocketAddr> {
114 self.local_addr()
115 }
116}