pub struct ReadonlyReactiveValue<T> { /* private fields */ }
Expand description
Holds the latest value emitted by a stream.
ReactiveValues automatically unsubscribe from the stream when they are destroyed, preventing the kinds of memory leaks common in reactive programming.
§Examples
use epoxy_streams::ReactiveValue;
let stream_host: epoxy_streams::Sink<i32> = epoxy_streams::Sink::new();
let stream = stream_host.get_stream();
let reactive_value = stream.map(|val| val * 100).to_reactive_value();
assert_eq!(*reactive_value.get(), 0);
stream_host.emit(1);
assert_eq!(*reactive_value.get(), 100);
stream_host.emit(3);
assert_eq!(*reactive_value.get(), 300);
use epoxy_streams::ReactiveValue;
let stream_host: epoxy_streams::Sink<i32> = epoxy_streams::Sink::new();
let stream = stream_host.get_stream();
let reactive_value = stream.map(|val| val * 100).to_reactive_value_with_default(1000);
assert_eq!(*reactive_value.get(), 1000);
stream_host.emit(100);
assert_eq!(*reactive_value.get(), 10000);
Trait Implementations§
Source§impl<T> Clone for ReadonlyReactiveValue<T>
impl<T> Clone for ReadonlyReactiveValue<T>
Source§impl<T> ReactiveValue<T> for ReadonlyReactiveValue<T>
impl<T> ReactiveValue<T> for ReadonlyReactiveValue<T>
Auto Trait Implementations§
impl<T> Freeze for ReadonlyReactiveValue<T>
impl<T> RefUnwindSafe for ReadonlyReactiveValue<T>
impl<T> !Send for ReadonlyReactiveValue<T>
impl<T> !Sync for ReadonlyReactiveValue<T>
impl<T> Unpin for ReadonlyReactiveValue<T>
impl<T> UnwindSafe for ReadonlyReactiveValue<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