[][src]Struct stream_multiplexer::Multiplexer

pub struct Multiplexer<St, Si> where
    St: 'static, 
{ /* fields omitted */ }

Implementations

impl<St, Si> Multiplexer<St, Si> where
    St: TryStream + Unpin,
    St::Ok: Clone,
    Si: Sink<St::Ok> + Unpin,
    Si::Error: Debug
[src]

pub fn new() -> Self[src]

Creates a Multiplexer

pub fn add_channel(
    &mut self,
    channel_id: ChannelId
) -> Result<(), MultiplexerError<Si::Error>>
[src]

Adds a channel id to the internal table used for validation checks.

Returns an error if channel already exists.

pub fn has_channel(&self, channel: ChannelId) -> bool[src]

Returns true if the channel id exists.

pub fn remove_channel(&mut self, channel: ChannelId) -> bool[src]

Removes a channel.

Returns true if found, false otherwise.

pub async fn send<'_>(
    &'_ self,
    stream_ids: impl IntoIterator<Item = StreamId>,
    data: St::Ok
) -> Vec<Result<StreamId, MultiplexerError<Si::Error>>>
[src]

Sends data to a set of stream_ids, waiting for them to be sent.

pub fn add_stream_pair(
    &mut self,
    sink: Si,
    stream: St,
    channel_id: ChannelId
) -> Result<StreamId, MultiplexerError<Si::Error>>
[src]

Adds stream to the channel and stores sink.

Returns a StreamId that represents the pair. It can be used in functions such as send() or change_stream_channel().

pub fn change_stream_channel(
    &self,
    stream_id: StreamId,
    channel_id: ChannelId
) -> Result<(), MultiplexerError<Si::Error>>
[src]

Signals to the stream that it should move to a given channel.

The channel change is not instantaneous. Calling .recv() on the stream's current channel may result in that channel receiving more of the stream's data.

pub fn remove_stream(&mut self, stream_id: StreamId) -> bool[src]

Removes the stream from the multiplexer

pub async fn recv<'_>(
    &'_ mut self,
    channel_id: ChannelId
) -> Result<(StreamId, Option<St::Item>), MultiplexerError<Si::Error>>
[src]

Receives the next packet available from a channel:

Returns a tuple of the stream's ID and it's data or an error.

Trait Implementations

impl<St, Si> Clone for Multiplexer<St, Si>[src]

impl<St: Debug, Si: Debug> Debug for Multiplexer<St, Si> where
    St: 'static, 
[src]

Auto Trait Implementations

impl<St, Si> !RefUnwindSafe for Multiplexer<St, Si>

impl<St, Si> Send for Multiplexer<St, Si> where
    Si: Send,
    St: Send

impl<St, Si> Sync for Multiplexer<St, Si> where
    Si: Send,
    St: Send

impl<St, Si> Unpin for Multiplexer<St, Si>

impl<St, Si> !UnwindSafe for Multiplexer<St, Si>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.