pub struct Derived<T> { /* private fields */ }Expand description
A cached value computed from other reactive values. It recomputes lazily, on the first read after a dependency changed, and notifies its own readers when that happens.
Implementations§
Source§impl<T> Derived<T>where
T: Clone + 'static,
impl<T> Derived<T>where
T: Clone + 'static,
Sourcepub fn new(compute: impl Fn() -> T + 'static) -> Derived<T>
pub fn new(compute: impl Fn() -> T + 'static) -> Derived<T>
Creates a derived value from compute, which runs on the first read.
use ravenrs_reactive::{Derived, State};
let count = State::new(2);
let c = count.clone();
let doubled = Derived::new(move || c.get() * 2);
assert_eq!(doubled.get(), 4);
count.set(5);
assert_eq!(doubled.get(), 10);Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Derived<T>
impl<T> !Send for Derived<T>
impl<T> !Sync for Derived<T>
impl<T> !UnwindSafe for Derived<T>
impl<T> Freeze for Derived<T>
impl<T> Unpin for Derived<T>
impl<T> UnsafeUnpin for Derived<T>
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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