Struct tange::deferred::Deferred

source ·
pub struct Deferred<A> { /* private fields */ }
Expand description

A Deferred is the core struct defining how computations are composed The type parameter indicates the type of data contained within the Deferred

Implementations§

Applies a function to a Deferred, returning a new Deferred. This is effectively a Functor.

use tange::deferred::Deferred;
use tange::scheduler::GreedyScheduler;

let def = Deferred::lift(vec![1u8, 2, 3, 4], "Vector".into());
let size = def.apply(|v| v.len());
let results = size.run(&GreedyScheduler::new());
assert_eq!(results, Some(4usize));

Joins two Deferred objects with a function, creating a new Deferred object.

use tange::deferred::Deferred;
use tange::scheduler::GreedyScheduler;

let left  = Deferred::lift(vec![1f32, 2., 3., 4.], "Vector".into());
let right  = Deferred::lift(10f32, "Num".into());
let multiplied: Deferred<Vec<f32>> = left.join(&right, 
       |l,r| l.iter().map(|x| x * r).collect());
let results = multiplied.run(&GreedyScheduler::new());
assert_eq!(results, Some(vec![10., 20., 30., 40.]));

Lifts a value into a Deferred object.

use tange::deferred::Deferred;
use tange::scheduler::GreedyScheduler;

let id = Deferred::lift("Some String".to_owned(), "String".into());
assert_eq!(id.run(&GreedyScheduler::new()), Some("Some String".into()));
 

Evaluates the Deferred object and dependency graph, returning the result of the computation.

use tange::deferred::Deferred;
use tange::scheduler::GreedyScheduler;

let a = Deferred::lift(1usize, "a".into());
let b = Deferred::lift(2usize, "b".into());
let c = a.join(&b, |x, y| x + y);
assert_eq!(c.run(&GreedyScheduler::new()), Some(3usize));
 

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.