Struct bidule::Stream
[−]
[src]
pub struct Stream<'a, Sig> { /* fields omitted */ }
A stream of signals.
A stream represents a composable signal producer. When you decide to send a signal down a stream, any other streams composed with that first stream will also receive the signal. This enables to construct more interesting and complex streams by composing them.
Methods
impl<'a, Sig> Stream<'a, Sig> where
Sig: 'a,
[src]
Sig: 'a,
fn new() -> Self
[src]
Create a new stream.
fn subscribe<F>(&self, subscriber: F) where
F: 'a + FnMut(&Sig),
[src]
F: 'a + FnMut(&Sig),
Subscribe a new listener for this stream’s signals.
This function enables to “observe” any signal flowing out of the stream. However, do not abuse this function, as its primary use is to build other combinators.
fn send(&self, signal: &Sig)
[src]
Send a signal down the stream.
fn map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig> where
F: 'a + Fn(&Sig) -> OutSig,
OutSig: 'a,
[src]
F: 'a + Fn(&Sig) -> OutSig,
OutSig: 'a,
Map any signals flowing out a stream.
Please note that this function is total: you cannot ignore signals. Even if you map
uninteresting signals to None
, you’ll still compose signals for those. If are interested
in filtering signals while mapping, have a look at the filter_map
function.
fn filter_map<F, OutSig>(&self, f: F) -> Stream<'a, OutSig> where
F: 'a + Fn(&Sig) -> Option<OutSig>,
OutSig: 'a,
[src]
F: 'a + Fn(&Sig) -> Option<OutSig>,
OutSig: 'a,
Filter and map signals flowing out a stream.
If you’re not interested in a specific signal, you can emit None
: no signal will be sent.
fn filter<F>(&self, pred: F) -> Self where
F: 'a + Fn(&Sig) -> bool,
[src]
F: 'a + Fn(&Sig) -> bool,
Filter the signals flowing out of a stream with a predicate.
fn fold<F, A>(&self, value: A, f: F) -> Stream<'a, A> where
F: 'a + Fn(A, &Sig) -> A,
A: 'a,
[src]
F: 'a + Fn(A, &Sig) -> A,
A: 'a,
Fold all signals flowing out of a stream into a stream of values.
fn merge(&self, rhs: &Self) -> Self
[src]
Merge two streams into one.
Merging streams enables you to perform later useful compositions, such as folding the merged results.
fn zip<SigRHS>(
&self,
rhs: &Stream<'a, SigRHS>
) -> Stream<'a, Either<Sig, SigRHS>> where
Sig: Clone,
SigRHS: 'a + Clone,
[src]
&self,
rhs: &Stream<'a, SigRHS>
) -> Stream<'a, Either<Sig, SigRHS>> where
Sig: Clone,
SigRHS: 'a + Clone,
Zip two streams with each other.
fn entangled<F, G, GSig>(f: F, g: G) -> (Self, Stream<'a, GSig>) where
F: 'a + Fn(&Sig) -> Option<GSig>,
G: 'a + Fn(&GSig) -> Option<Sig>,
GSig: 'a,
[src]
F: 'a + Fn(&Sig) -> Option<GSig>,
G: 'a + Fn(&GSig) -> Option<Sig>,
GSig: 'a,
Create a pair of entangled streams.
If any of the streams sends a signal, the other one receives it. However, be careful: since
the signals are defined in terms of each other, it’s quite easy to cause infinite loops if you
don’t have a well-defined bottom to your recursion. This is why you’re expected to return
Option<_>
signals.
fn sink(&self) -> Receiver<Sig> where
Sig: Clone,
[src]
Sig: Clone,
Sink a stream.
impl<'a, SigA, SigB> Stream<'a, Either<SigA, SigB>> where
SigA: 'static,
SigB: 'static,
[src]
SigA: 'static,
SigB: 'static,