Sink

Struct Sink 

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

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

Implementations§

Source§

impl<T> Sink<T>

Source

pub fn new() -> Sink<T>

Examples found in repository?
examples/event_stream.rs (line 15)
13    pub fn new() -> MyButton {
14        MyButton {
15            click_host: epoxy::Sink::new(),
16        }
17    }
Source

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

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.

Examples found in repository?
examples/event_stream.rs (line 20)
19    pub fn get_clicks(&self) -> epoxy::Stream<MouseButton> {
20        self.click_host.get_stream()
21    }
Source

pub fn emit(&self, value: T)

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

Examples found in repository?
examples/event_stream.rs (line 24)
23    pub fn click(&self, button: MouseButton) {
24        self.click_host.emit(button)
25    }
Source

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

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

Trait Implementations§

Source§

impl<T> Drop for Sink<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Sink<T>

§

impl<T> RefUnwindSafe for Sink<T>

§

impl<T> !Send for Sink<T>

§

impl<T> !Sync for Sink<T>

§

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.