pub trait Transport:
AsyncRead
+ AsyncWrite
+ Debug
+ Unpin
+ Send
+ Sync {
// Required methods
fn peer_addr(&self) -> Result<SocketAddr, Error>;
fn local_addr(&self) -> Result<SocketAddr, Error>;
}Expand description
A bidirectional byte pipe that a request/response cycle can run over.
The transport is the only part of the server that knows what is carrying
the bytes. Everything above this trait is protocol agnostic: a plain TCP
socket, a TLS session and a per-request duplex stream are the same thing to
the parsing pipeline once they are type erased behind Transport.
Implementations report their own socket metadata, so a transport without a socket identity (a duplex pair, an in-memory pipe) answers with an error instead of pretending to have an address.
Required Methods§
Sourcefn peer_addr(&self) -> Result<SocketAddr, Error>
fn peer_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the remote end of the transport.
§Returns
Result<SocketAddr, io::Error>- The remote address, or an error when the transport has no socket identity.
Sourcefn local_addr(&self) -> Result<SocketAddr, Error>
fn local_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the local end of the transport.
§Returns
Result<SocketAddr, io::Error>- The local address, or an error when the transport has no socket identity.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Transport for TcpStream
Implementation of Transport trait for the plain TCP socket.
impl Transport for TcpStream
Implementation of Transport trait for the plain TCP socket.
The socket is the reference transport: it already carries a socket identity, so its addresses are reported directly.
Source§fn peer_addr(&self) -> Result<SocketAddr, Error>
fn peer_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the remote end of the socket.
§Returns
Result<SocketAddr, io::Error>- The peer address of the socket.
Source§fn local_addr(&self) -> Result<SocketAddr, Error>
fn local_addr(&self) -> Result<SocketAddr, Error>
Reports the address of the local end of the socket.
§Returns
Result<SocketAddr, io::Error>- The local address of the socket.