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>
impl<T> Sink<T>
Sourcepub fn get_stream(&self) -> Stream<T>
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more