Skip to main content

Transport

Trait Transport 

Source
pub trait Transport:
    Any
    + AsyncRead
    + AsyncWrite
    + Unpin
    + Send
    + Sync
    + 'static {
    // Provided methods
    fn set_linger(&mut self, linger: Option<Duration>) -> Result<(), Error> { ... }
    fn set_nodelay(&mut self, nodelay: bool) -> Result<(), Error> { ... }
    fn set_ip_ttl(&mut self, ttl: u32) -> Result<(), Error> { ... }
    fn peer_addr(&self) -> Result<Option<SocketAddr>, Error> { ... }
    fn negotiated_alpn(&self) -> Option<Cow<'_, [u8]>> { ... }
}
Expand description

§The interface that the http protocol is communicated over.

This trait supports several common interfaces supported by tcp streams, but also can be implemented for other stream types. All trait functions are currently optional.

Note: Transport uses the AsyncWrite and AsyncRead traits from futures-lite, which differ from the tokio AsyncRead / AsyncWrite traits. Runtime adapters handle bridging these at the boundary.

Provided Methods§

Source

fn set_linger(&mut self, linger: Option<Duration>) -> Result<(), Error>

§Sets the linger duration of this transport by setting the SO_LINGER option

See std::net::TcpStream::set_linger Optional to implement.

§Errors

Return an error if this transport supports setting linger and attempting to do so is unsuccessful.

Source

fn set_nodelay(&mut self, nodelay: bool) -> Result<(), Error>

§Sets the value of the TCP_NODELAY option on this transport.

See std::net::TcpStream::set_nodelay. Optional to implement.

§Errors

Return an error if this transport supports setting nodelay and attempting to do so is unsuccessful.

Source

fn set_ip_ttl(&mut self, ttl: u32) -> Result<(), Error>

§Sets the value for the IP_TTL option on this transport.

See std::net::TcpStream::set_ttl Optional to implement

§Errors

Return an error if this transport supports setting ttl and attempting to do so is unsuccessful.

Source

fn peer_addr(&self) -> Result<Option<SocketAddr>, Error>

§Returns the socket address of the remote peer of this transport.
§Errors

Return an error if this transport supports retrieving the remote peer but attempting to do so is unsuccessful.

Source

fn negotiated_alpn(&self) -> Option<Cow<'_, [u8]>>

§The protocol negotiated via TLS ALPN with the peer, if any.

Used by the runtime adapter to dispatch between HTTP/1.1 and HTTP/2 on the same TLS listener (Some(b"h2") → HTTP/2, anything else → HTTP/1.1) and by the client to pick between HTTP/1.1 and HTTP/2 when speaking to a server.

The returned Cow borrows from self when the backend exposes the protocol as a borrowed slice (e.g. rustls) and is owned when the backend copies (e.g. native-tls). The default returns None so transports that don’t speak TLS — or don’t want to opt into ALPN-based dispatch — don’t need to implement it.

Trait Implementations§

Source§

impl Transport for Box<dyn Transport>

Source§

fn set_linger(&mut self, linger: Option<Duration>) -> Result<(), Error>

Sets the linger duration of this transport by setting the SO_LINGER option Read more
Source§

fn set_nodelay(&mut self, nodelay: bool) -> Result<(), Error>

Sets the value of the TCP_NODELAY option on this transport. Read more
Source§

fn set_ip_ttl(&mut self, ttl: u32) -> Result<(), Error>

Sets the value for the IP_TTL option on this transport. Read more
Source§

fn peer_addr(&self) -> Result<Option<SocketAddr>, Error>

Returns the socket address of the remote peer of this transport. Read more
Source§

fn negotiated_alpn(&self) -> Option<Cow<'_, [u8]>>

The protocol negotiated via TLS ALPN with the peer, if any. Read more

Implementations on Foreign Types§

Source§

impl Transport for H2Transport

Source§

fn negotiated_alpn(&self) -> Option<Cow<'_, [u8]>>

Source§

impl Transport for Box<dyn Transport>

Source§

fn set_linger(&mut self, linger: Option<Duration>) -> Result<(), Error>

Source§

fn set_nodelay(&mut self, nodelay: bool) -> Result<(), Error>

Source§

fn set_ip_ttl(&mut self, ttl: u32) -> Result<(), Error>

Source§

fn peer_addr(&self) -> Result<Option<SocketAddr>, Error>

Source§

fn negotiated_alpn(&self) -> Option<Cow<'_, [u8]>>

Implementors§

Source§

impl<T, U> Transport for Binding<T, U>
where T: Transport, U: Transport,