Computable

Trait Computable 

Source
pub trait Computable<T> {
    // Required method
    fn try_compute(&mut self) -> Completable<T>;

    // Provided methods
    fn compute_completable(&mut self) -> Completable<T> { ... }
    fn compute(&mut self) -> Cancellable<T> { ... }
    fn dyn_computable(self) -> DynComputable<T>
       where Self: Sized + 'static { ... }
}
Expand description

A generic trait implemented by types that represent a “computation”.

To advance the computation, repeatedly call Computable::try_compute until a value is returned. Once the value is returned, the computable becomes “exhausted” and will return Incomplete::Exhausted.

See also ComputableResult and crate::Computation.

Required Methods§

Source

fn try_compute(&mut self) -> Completable<T>

Try to advance this computation, returning a value once the computation is done.

Provided Methods§

Source

fn compute_completable(&mut self) -> Completable<T>

Advance this computation until it either completes, is canceled, or becomes exhausted, skipping over all suspended states.

This method is identical to repeatedly calling Computable::try_compute until it returns something other than Incomplete::Suspended.

Note that this method can loop forever if the computation never completes and keeps returning Incomplete::Suspended.

Source

fn compute(&mut self) -> Cancellable<T>

Advance this computation until completion, skipping over all suspended states.

§Panics

Panics if called on an exhausted computation, i.e., if Computable::try_compute returns Incomplete::Exhausted. If you want to handle exhaustion gracefully, use Computable::compute_completable instead.

Source

fn dyn_computable(self) -> DynComputable<T>
where Self: Sized + 'static,

Utility method to convert this Computable to a dynamic type.

Implementors§

Source§

impl<CONTEXT, STATE, OUTPUT> Computable<OUTPUT> for DynAlgorithm<CONTEXT, STATE, OUTPUT>

Source§

impl<CONTEXT, STATE, OUTPUT, STEP: ComputationStep<CONTEXT, STATE, OUTPUT>> Computable<OUTPUT> for Computation<CONTEXT, STATE, OUTPUT, STEP>

Source§

impl<ITEM, COLLECTION, G> Computable<COLLECTION> for Collector<ITEM, COLLECTION, G>
where COLLECTION: Default + Extend<ITEM>, G: Generatable<ITEM>,

Source§

impl<T> Computable<T> for ComputableIdentity<T>

Source§

impl<T> Computable<T> for DynComputable<T>