pub trait Transport {
type Error: Error + Send + Sync + 'static;
type Sender: Send + Sync + Clone;
type SendBuffer: Encoder + Send;
type SendFutureState: Send;
type Receiver: Send;
type RecvFutureState: Send;
type RecvBuffer: Decoder + Send;
// Required methods
fn split(self) -> (Self::Sender, Self::Receiver);
fn acquire(sender: &Self::Sender) -> Self::SendBuffer;
fn begin_send(
sender: &Self::Sender,
buffer: Self::SendBuffer,
) -> Self::SendFutureState;
fn poll_send(
future: Pin<&mut Self::SendFutureState>,
cx: &mut Context<'_>,
sender: &Self::Sender,
) -> Poll<Result<(), Self::Error>>;
fn close(sender: &Self::Sender);
fn begin_recv(receiver: &mut Self::Receiver) -> Self::RecvFutureState;
fn poll_recv(
future: Pin<&mut Self::RecvFutureState>,
cx: &mut Context<'_>,
receiver: &mut Self::Receiver,
) -> Poll<Result<Option<Self::RecvBuffer>, Self::Error>>;
}
Expand description
A transport layer which can send and receive messages.
The futures provided by this trait should be cancel-safe, which constrains their behavior:
- Operations should not partially complete.
- Operations should only complete during polling.
SendFuture
should return an Poll::Ready
with an error when polled after the transport is
closed.
Required Associated Types§
Sourcetype Sender: Send + Sync + Clone
type Sender: Send + Sync + Clone
The sender half of the transport. Dropping all of the senders for a transport should close the transport.
Sourcetype SendBuffer: Encoder + Send
type SendBuffer: Encoder + Send
The buffer type for senders.
Sourcetype SendFutureState: Send
type SendFutureState: Send
The future state for send operations.
Sourcetype RecvFutureState: Send
type RecvFutureState: Send
The future state for receive operations.
Sourcetype RecvBuffer: Decoder + Send
type RecvBuffer: Decoder + Send
The buffer type for receivers.
Required Methods§
Sourcefn split(self) -> (Self::Sender, Self::Receiver)
fn split(self) -> (Self::Sender, Self::Receiver)
Splits the transport into a sender and receiver.
Sourcefn acquire(sender: &Self::Sender) -> Self::SendBuffer
fn acquire(sender: &Self::Sender) -> Self::SendBuffer
Acquires an empty send buffer for the transport.
Sourcefn begin_send(
sender: &Self::Sender,
buffer: Self::SendBuffer,
) -> Self::SendFutureState
fn begin_send( sender: &Self::Sender, buffer: Self::SendBuffer, ) -> Self::SendFutureState
Begins sending a SendBuffer
over this transport.
Returns the state for a future which can be polled with poll_send
.
Sourcefn poll_send(
future: Pin<&mut Self::SendFutureState>,
cx: &mut Context<'_>,
sender: &Self::Sender,
) -> Poll<Result<(), Self::Error>>
fn poll_send( future: Pin<&mut Self::SendFutureState>, cx: &mut Context<'_>, sender: &Self::Sender, ) -> Poll<Result<(), Self::Error>>
Polls a SendFutureState
for completion with a sender.
Sourcefn begin_recv(receiver: &mut Self::Receiver) -> Self::RecvFutureState
fn begin_recv(receiver: &mut Self::Receiver) -> Self::RecvFutureState
Begins receiving a RecvBuffer
over this transport.
Returns the state for a future which can be polled with poll_recv
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.