pub trait Transport: 'static {
type Error: Error + Send + Sync + 'static;
type Sender: Send;
type SendBuffer: Send;
type Encoder<'b>: Encoder + Send
where Self: 'b;
type SendFuture<'s>: Future<Output = Result<(), Self::Error>> + Send
where Self: 's;
type Receiver: Send;
type RecvFuture<'r>: Future<Output = Result<Option<Self::RecvBuffer>, Self::Error>> + Send
where Self: 'r;
type RecvBuffer: Send;
type Decoder<'b>: Decoder<'b> + Send
where Self: 'b;
// Required methods
fn split(self) -> (Self::Sender, Self::Receiver);
fn acquire(sender: &Self::Sender) -> Self::SendBuffer;
fn encoder(buffer: &mut Self::SendBuffer) -> Self::Encoder<'_>;
fn send(
sender: &Self::Sender,
buffer: Self::SendBuffer,
) -> Self::SendFuture<'_>;
fn recv(receiver: &mut Self::Receiver) -> Self::RecvFuture<'_>;
fn decoder(buffer: &mut Self::RecvBuffer) -> Self::Decoder<'_>;
}
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.
Required Associated Types§
Sourcetype SendBuffer: Send
type SendBuffer: Send
The buffer type for senders.
Sourcetype SendFuture<'s>: Future<Output = Result<(), Self::Error>> + Send
where
Self: 's
type SendFuture<'s>: Future<Output = Result<(), Self::Error>> + Send where Self: 's
The future type for send operations.
Sourcetype RecvFuture<'r>: Future<Output = Result<Option<Self::RecvBuffer>, Self::Error>> + Send
where
Self: 'r
type RecvFuture<'r>: Future<Output = Result<Option<Self::RecvBuffer>, Self::Error>> + Send where Self: 'r
The future type for receive operations.
Sourcetype RecvBuffer: Send
type RecvBuffer: 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 encoder(buffer: &mut Self::SendBuffer) -> Self::Encoder<'_>
fn encoder(buffer: &mut Self::SendBuffer) -> Self::Encoder<'_>
Gets the encoder for a buffer.
Sourcefn send(sender: &Self::Sender, buffer: Self::SendBuffer) -> Self::SendFuture<'_>
fn send(sender: &Self::Sender, buffer: Self::SendBuffer) -> Self::SendFuture<'_>
Sends an encoded message over the transport.
Sourcefn recv(receiver: &mut Self::Receiver) -> Self::RecvFuture<'_>
fn recv(receiver: &mut Self::Receiver) -> Self::RecvFuture<'_>
Receives an encoded message over the transport.
Sourcefn decoder(buffer: &mut Self::RecvBuffer) -> Self::Decoder<'_>
fn decoder(buffer: &mut Self::RecvBuffer) -> Self::Decoder<'_>
Gets the decoder for a buffer.
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.