Struct carboxyl::Sink [] [src]

pub struct Sink<A> { /* fields omitted */ }

An event sink.

This primitive is a way of generating streams of events. One can send input values into a sink and generate a stream that fires all these inputs as events:

// A new sink
let sink = Sink::new();

// Make an iterator over a stream.
let mut events =;

// Send a value into the sink

// The stream
assert_eq!(, Some(5));

You can also feed a sink with an iterator:

assert_eq!(events.take(4).collect::<Vec<_>>(), vec![20, 21, 22, 23]);

Asynchronous calls

It is possible to send events into the sink asynchronously using the methods send_async and feed_async. Note though, that this will void some guarantees on the order of events. In the following example, it is unclear, which event is the first in the stream:

let sink = Sink::new();
let mut events =;
let first =;
assert!(first == 13 || first == 22);

feed_async provides a workaround, as it preserves the order of events from the iterator. However, any event sent into the sink after a call to it, may come at any point between the iterator events.


impl<A: Send + Sync> Sink<A>

Create a new sink.

Generate a stream that fires all events sent into the sink.

impl<A: Send + Sync + Clone + 'static> Sink<A>

Asynchronous send.

Same as send, but it spawns a new thread to process the updates to dependent streams and signals.

Feed values from an iterator into the sink.

This method feeds events into the sink from an iterator.

Asynchronous feed.

This is the same as feed, but it does not block, since it spawns the feeding as a new task. This is useful, if the provided iterator is large or even infinite (e.g. an I/O event loop).

Send a value into the sink.

When a value is sent into the sink, an event is fired in all dependent streams.

Trait Implementations

impl<A> Clone for Sink<A>

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more