Struct vertigo::Computed

source ·
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: Clone + 'static> Computed<T>

source

pub fn from<F: Fn(&Context) -> T + 'static>(get_value: F) -> Computed<T>

source

pub fn get_id(&self) -> GraphId

source

pub fn get(&self, context: &Context) -> T

source

pub fn map<K: Clone + 'static, F: 'static + Fn(T) -> K>( &self, fun: F ) -> Computed<K>

source

pub fn id(&self) -> GraphId

source§

impl<T: 'static + PartialEq + Clone> Computed<T>

source

pub fn subscribe<R: 'static, F: Fn(T) -> R + 'static>( self, call: F ) -> DropResource

source§

impl<T: 'static + Clone> Computed<T>

source

pub fn subscribe_all<R: 'static, F: Fn(T) -> R + 'static>( self, call: F ) -> DropResource

source§

impl<T: 'static + PartialEq + Clone> Computed<T>

source

pub fn render_value(&self, render: impl Fn(T) -> DomNode + 'static) -> DomNode

source

pub fn render_value_option( &self, render: impl Fn(T) -> Option<DomNode> + 'static ) -> DomNode

source§

impl<T: PartialEq + Clone + 'static, L: IntoIterator<Item = T> + Clone + PartialEq + 'static> Computed<L>

source

pub fn render_list<K: Eq + Hash>( &self, get_key: impl Fn(&T) -> K + 'static, render: impl Fn(&T) -> DomNode + 'static ) -> DomNode

Trait Implementations§

source§

impl<T: Clone + 'static> Clone for Computed<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for &Computed<T>

source§

impl<T: ToString + Clone + PartialEq + 'static> EmbedDom for Computed<T>

source§

impl<T: Clone + 'static> From<&T> for Computed<T>

source§

fn from(value: &T) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Computed<String>

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl<R> From<Computed<Rc<dyn Fn() -> R>>> for Callback<R>

source§

fn from(value: Computed<Rc<dyn Fn() -> R + 'static>>) -> Self

Converts to this type from the input type.
source§

impl<T, R> From<Computed<Rc<dyn Fn(T) -> R>>> for Callback1<T, R>

source§

fn from(value: Computed<Rc<dyn Fn(T) -> R + 'static>>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone + 'static> From<T> for Computed<T>

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T: Clone + 'static> From<Value<T>> for Computed<T>

source§

fn from(val: Value<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Clone + 'static> PartialEq for Computed<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Clone + 'static> ToComputed<Resource<Rc<T>>> for Computed<Resource<T>>

source§

impl<T: Clone + 'static> ToComputed<T> for &Computed<T>

source§

impl<T: Clone + 'static> ToComputed<T> for 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> 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<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.