pub trait StreamMuxer {
    type Substream: AsyncRead + AsyncWrite;
    type Error: Error;

    fn poll_inbound(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Self::Substream, Self::Error>>; fn poll_outbound(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Self::Substream, Self::Error>>; fn poll_close(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>; fn poll(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<StreamMuxerEvent, Self::Error>>; }
Expand description

Provides multiplexing for a connection by allowing users to open substreams.

A substream created by a StreamMuxer is a type that implements [AsyncRead] and [AsyncWrite]. The StreamMuxer itself is modelled closely after [AsyncWrite]. It features poll-style functions that allow the implementation to make progress on various tasks.

Required Associated Types§

Type of the object that represents the raw substream where data can be read and written.

Error type of the muxer

Required Methods§

Poll for new inbound substreams.

This function should be called whenever callers are ready to accept more inbound streams. In other words, callers may exercise back-pressure on incoming streams by not calling this function if a certain limit is hit.

Poll for a new, outbound substream.

Poll to close this StreamMuxer.

After this has returned Poll::Ready(Ok(())), the muxer has become useless and may be safely dropped.

Note: You are encouraged to call this method and wait for it to return Ready, so that the remote is properly informed of the shutdown. However, apart from properly informing the remote, there is no difference between this and immediately dropping the muxer.

Poll to allow the underlying connection to make progress.

In contrast to all other poll-functions on StreamMuxer, this function MUST be called unconditionally. Because it will be called regardless, this function can be used by implementations to return events about the underlying connection that the caller MUST deal with.

Implementors§