Struct multi_consumer_stream::OwnerMCS
[−]
[src]
pub struct OwnerMCS<S: Stream, K, F>(_);
A wrapper around a stream, that allows obtaining multiple handles for reading from that stream.
A KeyHandle
only receives items for which the key_fn
returns a
certain key. All other items are emitted on a DefaultHandle
.
Methods
impl<S, K, F> OwnerMCS<S, K, F> where
S: Stream,
K: Copy + Eq + Hash,
F: Fn(&S::Item) -> K,
[src]
S: Stream,
K: Copy + Eq + Hash,
F: Fn(&S::Item) -> K,
fn new(stream: S, key_fn: F) -> OwnerMCS<S, K, F>
[src]
Create a new OwnerMCS
, wrapping stream
.
The key_fn
is invoked for each item emitted by the stream. Its return
value is used to give the item to the correct handle. If the return
value does not match the key of any handle, the item is emitted on a
DefaultHandle
.
fn key_handle(&self, key: K) -> KeyHandle<S, K, F>
[src]
Create a KeyHandle
to the underlying stream. The handle receives all
items for which the key_fn
returns key
.
Panics if there is already a handle for that key.
fn try_key_handle(&self, key: K) -> Option<KeyHandle<S, K, F>>
[src]
Create a KeyHandle
to the underlying stream. The handle receives all
items for which the key_fn
returns key
. This returns None
if there
is already a handle for the given key.
fn default_handle(&self) -> DefaultHandle<S, K, F>
[src]
Create a DefaultHandle
to the underlying stream. The handle receives
all items for which there is no KeyHandle
.
The behaviour of multiple DefaultHandles
polling at the same time is
safe, but unspecified. Just don't do that.