Trait Transport

Source
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§

Source

type Error: Error + Send + Sync + 'static

The error type for the transport.

Source

type Sender: Send + Sync + Clone

The sender half of the transport. Dropping all of the senders for a transport should close the transport.

Source

type SendBuffer: Encoder + Send

The buffer type for senders.

Source

type SendFutureState: Send

The future state for send operations.

Source

type Receiver: Send

The receiver half of the transport.

Source

type RecvFutureState: Send

The future state for receive operations.

Source

type RecvBuffer: Decoder + Send

The buffer type for receivers.

Required Methods§

Source

fn split(self) -> (Self::Sender, Self::Receiver)

Splits the transport into a sender and receiver.

Source

fn acquire(sender: &Self::Sender) -> Self::SendBuffer

Acquires an empty send buffer for the transport.

Source

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.

Source

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.

Source

fn close(sender: &Self::Sender)

Closes the transport.

Source

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.

Source

fn poll_recv( future: Pin<&mut Self::RecvFutureState>, cx: &mut Context<'_>, receiver: &mut Self::Receiver, ) -> Poll<Result<Option<Self::RecvBuffer>, Self::Error>>

Polls a RecvFutureState for completion with a receiver.

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.

Implementations on Foreign Types§

Source§

impl Transport for Channel

Source§

type Error = Status

Source§

type Sender = Sender

Source§

type SendBuffer = Buffer

Source§

type SendFutureState = SendFutureState

Source§

type Receiver = Receiver

Source§

type RecvFutureState = RecvFutureState

Source§

type RecvBuffer = RecvBuffer

Source§

fn split(self) -> (Self::Sender, Self::Receiver)

Source§

fn acquire(_: &Self::Sender) -> Self::SendBuffer

Source§

fn begin_send( _: &Self::Sender, buffer: Self::SendBuffer, ) -> Self::SendFutureState

Source§

fn poll_send( future_state: Pin<&mut Self::SendFutureState>, _: &mut Context<'_>, sender: &Self::Sender, ) -> Poll<Result<(), Self::Error>>

Source§

fn close(sender: &Self::Sender)

Source§

fn begin_recv(_: &mut Self::Receiver) -> Self::RecvFutureState

Source§

fn poll_recv( future_state: Pin<&mut Self::RecvFutureState>, cx: &mut Context<'_>, receiver: &mut Self::Receiver, ) -> Poll<Result<Option<Self::RecvBuffer>, Self::Error>>

Implementors§