pub struct Computed<T: Clone> { /* private fields */ }
Expand description
A reactive value that is read-only and computed by dependency graph.
§Computed directly from Value
use vertigo::{Computed, Value, transaction};
let value = Value::new(5);
let comp = value.to_computed();
transaction(|context| {
assert_eq!(comp.get(context), 5);
});
// Can't do that
// comp.set(10);
§Computed from Value by provided function
use vertigo::{Computed, Value, transaction};
let value = Value::new(2);
let comp_2 = {
let v = value.clone();
Computed::from(move |context| v.get(context) * 2)
};
transaction(|context| {
assert_eq!(comp_2.get(context), 4);
});
value.set(6);
transaction(|context| {
assert_eq!(comp_2.get(context), 12);
});
Implementations§
source§impl<T: 'static + PartialEq + Clone> Computed<T>
impl<T: 'static + PartialEq + Clone> Computed<T>
pub fn subscribe<R: 'static, F: Fn(T) -> R + 'static>( self, call: F ) -> DropResource
source§impl<T: 'static + Clone> Computed<T>
impl<T: 'static + Clone> Computed<T>
pub fn subscribe_all<R: 'static, F: Fn(T) -> R + 'static>( self, call: F ) -> DropResource
Trait Implementations§
source§impl<T: Clone + 'static> PartialEq for Computed<T>
impl<T: Clone + 'static> PartialEq for Computed<T>
source§impl<T: Clone + 'static> ToComputed<T> for &Computed<T>
impl<T: Clone + 'static> ToComputed<T> for &Computed<T>
fn to_computed(&self) -> Computed<T>
source§impl<T: Clone + 'static> ToComputed<T> for Computed<T>
impl<T: Clone + 'static> ToComputed<T> for Computed<T>
fn to_computed(&self) -> Computed<T>
Auto Trait Implementations§
impl<T> Freeze for Computed<T>
impl<T> !RefUnwindSafe for Computed<T>
impl<T> !Send for Computed<T>
impl<T> !Sync for Computed<T>
impl<T> Unpin for Computed<T>
impl<T> !UnwindSafe for Computed<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