Trait Transport

pub trait Transport {
    type Error: Clone + Error + Send + Sync + 'static;
    type Shared: Send + Sync;
    type Exclusive: Send;
    type SendBuffer: Encoder + Send;
    type SendFutureState: Send;
    type RecvFutureState: Send;
    type RecvBuffer: Decoder + Send;

    // Required methods
    fn split(self) -> (Self::Shared, Self::Exclusive);
    fn acquire(shared: &Self::Shared) -> Self::SendBuffer;
    fn begin_send(
        shared: &Self::Shared,
        buffer: Self::SendBuffer,
    ) -> Self::SendFutureState;
    fn poll_send(
        future: Pin<&mut Self::SendFutureState>,
        cx: &mut Context<'_>,
        shared: &Self::Shared,
    ) -> Poll<Result<(), Option<Self::Error>>>;
    fn begin_recv(
        shared: &Self::Shared,
        exclusive: &mut Self::Exclusive,
    ) -> Self::RecvFutureState;
    fn poll_recv(
        future: Pin<&mut Self::RecvFutureState>,
        cx: &mut Context<'_>,
        shared: &Self::Shared,
        exclusive: &mut Self::Exclusive,
    ) -> Poll<Result<Self::RecvBuffer, Option<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 Poll::Ready with an error when polled after the transport is closed.

Required Associated Types§

type Error: Clone + Error + Send + Sync + 'static

The error type for the transport.

type Shared: Send + Sync

The shared part of the transport. It is provided by shared reference while sending and receiving. For an MPSC, this would contain a sender.

type Exclusive: Send

The exclusive part of the transport. It is provided by mutable reference only while receiving. For an MPSC, this would contain a receiver.

type SendBuffer: Encoder + Send

The buffer type for sending.

type SendFutureState: Send

The future state for send operations.

type RecvFutureState: Send

The future state for receive operations.

type RecvBuffer: Decoder + Send

The buffer type for receivers.

Required Methods§

fn split(self) -> (Self::Shared, Self::Exclusive)

Splits the transport into shared and exclusive pieces.

fn acquire(shared: &Self::Shared) -> Self::SendBuffer

Acquires an empty send buffer for the transport.

fn begin_send( shared: &Self::Shared, 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.

fn poll_send( future: Pin<&mut Self::SendFutureState>, cx: &mut Context<'_>, shared: &Self::Shared, ) -> Poll<Result<(), Option<Self::Error>>>

Polls a SendFutureState for completion with the shared part of the transport.

When ready, polling returns one of three values:

  • Ok(()) if the buffer was successfully sent.
  • Err(None) if the connection was terminated normally (e.g. with PEER_CLOSED).
  • Err(Some(error)) if the connection was terminated abnormally.

fn begin_recv( shared: &Self::Shared, exclusive: &mut Self::Exclusive, ) -> Self::RecvFutureState

Begins receiving a RecvBuffer over this transport.

Returns the state for a future which can be polled with poll_recv.

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

Polls a RecvFutureState for completion with a receiver.

When ready, polling returns one of three values:

  • Ok(buffer) if buffer was successfully received.
  • Err(None) if the connection was terminated normally (e.g. with PEER_CLOSED).
  • Err(Some(error)) if the connection was terminated abnormally.

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.

Implementors§

§

impl Transport for Channel

§

impl Transport for Mpsc

§

type Error = Error

§

type Shared = Shared

§

type SendBuffer = Vec<WireU64>

§

type SendFutureState = SendFutureState

§

type Exclusive = Exclusive

§

type RecvFutureState = RecvFutureState

§

type RecvBuffer = RecvBuffer