pub trait AsyncTransport {
    type Error;

    // Required methods
    fn receive_poll(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Message, Self::Error>>;
    fn send_poll_ready(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>;
    fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>;
    fn send_poll_flush(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>;
}
Expand description

Bidirectional asynchronous message transport.

This trait represents the core abstraction used throughout Aldrin for communication between clients and the broker. It is essentially a combination of FuturesStream trait for receiving Messages and the Sink trait for sending.

Implementations must be reliable and ordered. Reliable means that Messages must not get corrupted. Ordered means that Messages must be delivered in the same order they were sent.

Typical implementations include:

  • TCP/IP across a network.
  • Unix domain sockets (SOCK_STREAM) between processes on a single machine.
  • Channels inside a single process.

§Shutdown

Transports shut down only implicitly when dropped or in the case of errors. There is no explicit shutdown method, because the Aldrin protocol defines the Shutdown message, after which users of this trait are expected to drop the transport. Any unexpected shutdown must be signaled with an Error by the implementation.

§Errors

All methods may return an Error at any time. Afterwards, the transport should be considered unusable. Implementations may panic in any further method calls.

Required Associated Types§

source

type Error

Error type when sending or receiving messages.

Required Methods§

source

fn receive_poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Message, Self::Error>>

Attempts to receive the next message.

source

fn send_poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Prepares the transport for sending a message.

This method must be called before sending a Message with send_start. Only when it returns Poll::Ready(Ok(())) is the transport ready to start sending a single Message.

The transport may be implicitly flushed, fully or partially, when this method is called.

source

fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>

Begins sending a message.

Every call to this method must be preceded by a successful call to send_poll_ready.

Sending a Message may flush the transport, but does not necessarily do so. Thus, even when Ok(()) is returned, the Message may not yet be delivered to the remote end of the transport. Use send_poll_flush to explicitly flush the transport.

source

fn send_poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to flush the transport.

Flushing must deliver all prior Messages to the remote end of the transport.

Implementations on Foreign Types§

source§

impl<T> AsyncTransport for &mut T
where T: AsyncTransport + Unpin + ?Sized,

§

type Error = <T as AsyncTransport>::Error

source§

fn receive_poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Message, Self::Error>>

source§

fn send_poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

source§

fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>

source§

fn send_poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

source§

impl<T> AsyncTransport for Box<T>
where T: AsyncTransport + Unpin + ?Sized,

§

type Error = <T as AsyncTransport>::Error

source§

fn receive_poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Message, Self::Error>>

source§

fn send_poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

source§

fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>

source§

fn send_poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

source§

impl<T> AsyncTransport for Pin<T>

§

type Error = <<T as Deref>::Target as AsyncTransport>::Error

source§

fn receive_poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Message, Self::Error>>

source§

fn send_poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

source§

fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>

source§

fn send_poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Implementors§