[][src]Struct epoxy_streams::Sink

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

A Sink is an object used to create a Stream. If you have ever visited a kitchen or bathroom you have probably observed this phenomena already. In more technical terms, Sinks are the 'write' part of functional reactive programming, and Streams are the 'read' part.

Examples

use std::sync::{Arc, Mutex};

let stream_host: epoxy_streams::Sink<i32> = epoxy_streams::Sink::new();
let stream = stream_host.get_stream();

let last_value = Arc::new(Mutex::new(0_i32));
let last_value_write = last_value.clone();

let subscription = stream.subscribe(move |val| {
    *last_value_write.lock().unwrap() = *val;
});

stream_host.emit(1);
assert_eq!(*last_value.lock().unwrap(), 1);

stream_host.emit(100);
assert_eq!(*last_value.lock().unwrap(), 100);

Methods

impl<T> Sink<T>[src]

pub fn new() -> Sink<T>[src]

pub fn get_stream(&self) -> Stream<T>[src]

Returns the Stream that emits values from this Sink. Usually the Stream will be exposed as a public API while the Sink will be kept private, however there are certainly exceptions to this pattern.

pub fn emit(&self, value: T)[src]

Emits a new value from this Sink, which will broadcast out to any Subscriber to the stream returned by the get_stream function.

pub fn emit_rc(&self, value: Arc<T>)[src]

Same logic as emit, but takes an existing Arc pointer (Epoxy streams use Arc pointers internally, so this saves a Copy).

Trait Implementations

impl<T> Drop for Sink<T>[src]

Auto Trait Implementations

impl<T> !Send for Sink<T>

impl<T> !Sync for Sink<T>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]