BoundValueComputeExt

Trait BoundValueComputeExt 

Source
pub trait BoundValueComputeExt: Sized {
    // Required method
    fn compute<TResultValue, TComputeFn>(
        &self,
        map_fn: TComputeFn,
    ) -> BindRef<TResultValue>
       where TResultValue: 'static + Clone + Send,
             TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue;
}
Expand description

Provides the compute() function for bindings and compatible types

Required Methods§

Source

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue,

Transforms the value of this binding using a compute function

This is generally used as a convenience function. It’s often necessary to create copies of the bindings and move them into the closure for computed(), which can add a lot of extra code and requires some sort of naming convention to distinguish the originals and the copies.

let some_binding        = bind(1);
let also_some_binding   = some_binding.clone();
let mapped              = computed(move || also_some_binding.get() + 1);

The clone can be avoided using the compute() function:

let some_binding    = bind(1);
let mapped          = some_binding.compute(|val| val.get() + 1);

This is supported on tuples of bindings too:

let some_binding    = bind(1);
let another_binding = bind(2);
let mapped          = (some_binding, another_binding)
    .compute(|(some_binding, another_binding)| some_binding.get() + another_binding.get());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<TBindingA, TBindingB> BoundValueComputeExt for (TBindingA, TBindingB)
where TBindingA: 'static + Clone + Bound, TBindingB: 'static + Clone + Bound,

Source§

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue,

Source§

impl<TBindingA, TBindingB, TBindingC> BoundValueComputeExt for (TBindingA, TBindingB, TBindingC)
where TBindingA: 'static + Clone + Bound, TBindingB: 'static + Clone + Bound, TBindingC: 'static + Clone + Bound,

Source§

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue,

Source§

impl<TBindingA, TBindingB, TBindingC, TBindingD> BoundValueComputeExt for (TBindingA, TBindingB, TBindingC, TBindingD)
where TBindingA: 'static + Clone + Bound, TBindingB: 'static + Clone + Bound, TBindingC: 'static + Clone + Bound, TBindingD: 'static + Clone + Bound,

Source§

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue,

Source§

impl<TBindingA, TBindingB, TBindingC, TBindingD, TBindingE> BoundValueComputeExt for (TBindingA, TBindingB, TBindingC, TBindingD, TBindingE)
where TBindingA: 'static + Clone + Bound, TBindingB: 'static + Clone + Bound, TBindingC: 'static + Clone + Bound, TBindingD: 'static + Clone + Bound, TBindingE: 'static + Clone + Bound,

Source§

fn compute<TResultValue, TComputeFn>( &self, map_fn: TComputeFn, ) -> BindRef<TResultValue>
where TResultValue: 'static + Clone + Send, TComputeFn: 'static + Send + Sync + Fn(&Self) -> TResultValue,

Implementors§

Source§

impl<TBinding> BoundValueComputeExt for TBinding
where TBinding: 'static + Clone + Bound,