Skip to main content

Multiplexer

Struct Multiplexer 

Source
pub struct Multiplexer<St, Si>
where St: 'static,
{ /* private fields */ }
Expand description

Implementations§

Source§

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

Source

pub fn new() -> Self

Creates a Multiplexer

Source

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

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

Returns an error if channel already exists.

Source

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

Returns true if the channel id exists.

Source

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

Removes a channel.

Returns true if found, false otherwise.

Source

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

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

Source

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

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().

Source

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

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.

Source

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

Removes the stream from the multiplexer

Source

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

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§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<St, Si: Debug> Debug for Multiplexer<St, Si>
where St: 'static + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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> UnsafeUnpin for Multiplexer<St, Si>

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.