pub struct Computation<T>{ /* private fields */ }
Expand description
Computation
represent a computation in the graph, with a static structures. Only
the variable values can be changed.
let v1 = Variable::<u32>::new(1);
let v2 = Variable::<u32>::new(2);
let v3 = Variable::<u32>::new(3);
// Create a new computation `c1` with `v1`, `v2` and `v3` as variables.
let c1 = Computation::<u32>::new(|(a, b, c)| a + b + c, (&v1, &v2, &v3));
println!("{} == 6", *c1.read_result());
// Change in `v1` change the result of `c1`.
v1.set(4);
println!("{} == 9", *c1.read_result());
Computation can also be used as input to other computation, and give access to intermediary results:
let v1 = Variable::<u32>::new(1);
let v2 = Variable::<u32>::new(2);
let v3 = Variable::<u32>::new(3);
// Create a new computation `c1` with `v1` and `v2` as variables.
let c1 = Computation::<u32>::new(|(a, b)| a + b, (&v1, &v2));
println!("{} == 3", *c1.read_result());
// Create a new computation `c2` which uses the result of `c1` and the variable `v3`.
let c2 = Computation::<u32>::new(|(a, b)| a + b, (&c1, &v3));
println!("{} == 6", *c1.read_result());
// Change in the value `v1` also changes the result of `c2`.
v1.set(4);
println!("{} == 6", *c1.read_result());
println!("{} == 9", *c2.read_result());
Implementations§
Source§impl<T> Computation<T>
impl<T> Computation<T>
Sourcepub fn new<TVars>(
formula: impl for<'a> Fn(TVars::FunctorArgument<'a>) -> T + 'static + Send + Sync,
tvars: TVars,
) -> Selfwhere
TVars: ComputationBuilder<T>,
pub fn new<TVars>(
formula: impl for<'a> Fn(TVars::FunctorArgument<'a>) -> T + 'static + Send + Sync,
tvars: TVars,
) -> Selfwhere
TVars: ComputationBuilder<T>,
Create a new computation with the given formula and a static set of variables.
Sourcepub fn read_result<'a>(&'a self) -> impl Deref<Target = T> + 'a
pub fn read_result<'a>(&'a self) -> impl Deref<Target = T> + 'a
Get the result of the computation. Re-compute it if outdated.
Trait Implementations§
Source§impl<T> Debug for Computation<T>
impl<T> Debug for Computation<T>
Source§impl<T> PartialEq<T> for Computation<T>
impl<T> PartialEq<T> for Computation<T>
Source§impl<T> PartialEq for Computation<T>
impl<T> PartialEq for Computation<T>
Source§impl<T> PartialOrd<T> for Computation<T>
impl<T> PartialOrd<T> for Computation<T>
Auto Trait Implementations§
impl<T> Freeze for Computation<T>
impl<T> RefUnwindSafe for Computation<T>
impl<T> Send for Computation<T>
impl<T> Sync for Computation<T>
impl<T> Unpin for Computation<T>
impl<T> UnwindSafe for Computation<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