Struct Sink

Source
pub struct Sink<T: 'static> { /* private fields */ }
Expand description

A sink is a producer of events. Created by Stream::sink().

Implementations§

Source§

impl<T> Sink<T>

Source

pub fn stream(&self) -> Stream<T>

Get a stream of events from this sink. One stream instance is created for each call, and they all receive the events from the sink.

let sink = froop::Stream::sink();

let stream1 = sink.stream();
let stream2 = sink.stream();

let coll1 = stream1.collect();
let coll2 = stream1.collect();

sink.update(42);
sink.end();

assert_eq!(coll1.wait(), vec![42]);
assert_eq!(coll2.wait(), vec![42]);
Source

pub fn update(&self, next: T)

Update a value into this sink.

The execution of the combinators “hanging” off this sink is (thread safe) and synchronous. In other words, there is nothing in froop itself that will still be “to do” once the update() call returns.

Each value is wrapped in an Option towards subscribers of the streams.

let sink = froop::Stream::sink();
let stream = sink.stream();

stream.subscribe(|v| {
    // v is Some(0), Some(1), None
});

sink.update(0);
sink.update(1);
sink.end();
Source

pub fn end(self)

End the stream of events. Consumes the instance since no more values are to go into it.

Subscribers will se a None value.

Every stream hanging directly off this sink will also end. The exception is streams combining input from multiple source streams.

Auto Trait Implementations§

§

impl<T> Freeze for Sink<T>

§

impl<T> RefUnwindSafe for Sink<T>

§

impl<T> Send for Sink<T>
where T: Send,

§

impl<T> Sync for Sink<T>
where T: Send,

§

impl<T> Unpin for Sink<T>

§

impl<T> UnwindSafe for Sink<T>

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