From 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 Mon Sep 17 00:00:00 2001 From: Date: Mon, 29 Jun 2015 20:16:15 +0000 Subject: Update documentation --- carboxyl/struct.Sink.html | 172 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 carboxyl/struct.Sink.html (limited to 'carboxyl/struct.Sink.html') diff --git a/carboxyl/struct.Sink.html b/carboxyl/struct.Sink.html new file mode 100644 index 0000000..742e070 --- /dev/null +++ b/carboxyl/struct.Sink.html @@ -0,0 +1,172 @@ + + + + + + + + + + carboxyl::Sink - Rust + + + + + + + + + + + + + + + +
+

Struct carboxyl::Sink + + [] + + [src]

+
pub struct Sink<A> {
+    // some 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 = sink.stream().events();
+
+// Send a value into the sink
+sink.send(5);
+
+// The stream
+assert_eq!(events.next(), Some(5));
+
+ +

You can also feed a sink with an iterator:

+
+sink.feed(20..40);
+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 = sink.stream().events();
+sink.send_async(13);
+sink.send_async(22);
+let first = events.next().unwrap();
+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.

+

Methods

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

fn new() -> Sink<A>

+

Create a new sink.

+

fn stream(&self) -> Stream<A>

+

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

+

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

fn send_async(&self, a: A)

+

Asynchronous send.

+ +

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

+

fn feed<I: IntoIterator<Item=A>>(&self, iterator: I)

+

Feed values from an iterator into the sink.

+ +

This method feeds events into the sink from an iterator.

+

fn feed_async<I: IntoIterator<Item=A> + Send + 'static>(&self, iterator: I)

+

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

+

fn send(&self, a: A)

+

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>

fn clone(&self) -> Sink<A>

+

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

+
+ + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3