async_io_helper/
connected.rs

1use std::net::SocketAddr;
2use tokio::net::TcpStream;
3
4/// Trait that connected IO resources implement.
5///
6/// The goal for this trait is to allow users to implement
7/// custom IO types that can still provide the same connection
8/// metadata.
9pub trait Connected {
10    /// Return the remote address this IO resource is connected too.
11    fn remote_addr(&self) -> Option<SocketAddr> {
12        None
13    }
14}
15
16impl Connected for TcpStream {
17    fn remote_addr(&self) -> Option<SocketAddr> {
18        self.peer_addr().ok()
19    }
20}