pub trait Transport<A: Address>:
Send
+ Sync
+ Unpin
+ 'static {
type Io: AsyncRead + AsyncWrite + PeerAddress<A> + Send + Unpin;
type Stats: Default + Debug + Send + Sync + for<'a> TryFrom<&'a Self::Io, Error: Debug>;
type Error: Error + From<Error> + Send + Sync;
type Connect: Future<Output = Result<Self::Io, Self::Error>> + Send;
type Accept: Future<Output = Result<Self::Io, Self::Error>> + Send + Unpin;
type Control: Send + Sync + Unpin;
// Required methods
fn local_addr(&self) -> Option<A>;
fn bind<'life0, 'async_trait>(
&'life0 mut self,
addr: A,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn connect(&mut self, addr: A) -> Self::Connect;
fn poll_accept(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Self::Accept>;
// Provided method
fn on_control(&mut self, _ctrl: Self::Control) { ... }
}Expand description
A transport provides connection-oriented communication between two peers through ordered and reliable streams of bytes.
It provides an interface to manage both inbound and outbound connections.
Required Associated Types§
Sourcetype Io: AsyncRead + AsyncWrite + PeerAddress<A> + Send + Unpin
type Io: AsyncRead + AsyncWrite + PeerAddress<A> + Send + Unpin
The result of a successful connection.
The output type is transport-specific, and can be a handle to directly write to the connection, or it can be a substream multiplexer in the case of stream protocols.
Sourcetype Stats: Default + Debug + Send + Sync + for<'a> TryFrom<&'a Self::Io, Error: Debug>
type Stats: Default + Debug + Send + Sync + for<'a> TryFrom<&'a Self::Io, Error: Debug>
The statistics for the transport (specifically its underlying IO object).
Sourcetype Error: Error + From<Error> + Send + Sync
type Error: Error + From<Error> + Send + Sync
An error that occurred when setting up the connection.
Sourcetype Connect: Future<Output = Result<Self::Io, Self::Error>> + Send
type Connect: Future<Output = Result<Self::Io, Self::Error>> + Send
A pending output for an outbound connection, obtained when calling Transport::connect.
Required Methods§
Sourcefn local_addr(&self) -> Option<A>
fn local_addr(&self) -> Option<A>
Returns the local address this transport is bound to (if it is bound).
Sourcefn bind<'life0, 'async_trait>(
&'life0 mut self,
addr: A,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn bind<'life0, 'async_trait>(
&'life0 mut self,
addr: A,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Binds to the given address.
Sourcefn connect(&mut self, addr: A) -> Self::Connect
fn connect(&mut self, addr: A) -> Self::Connect
Connects to the given address, returning a future representing a pending outbound connection.
Sourcefn poll_accept(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Accept>
fn poll_accept(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Accept>
Poll for incoming connections. If an inbound connection is received, a future representing
a pending inbound connection is returned. The future will resolve to Transport::Accept.
Provided Methods§
Sourcefn on_control(&mut self, _ctrl: Self::Control)
fn on_control(&mut self, _ctrl: Self::Control)
Applies a control-plane message to the transport. It is expected to update internal state only and should not perform long-running operations.