Collector

Struct Collector 

Source
pub struct Collector<ITEM, COLLECTION, G = DynGeneratable<ITEM>>
where COLLECTION: Default + Extend<ITEM>, G: Generatable<ITEM>,
{ /* private fields */ }
Expand description

A Computable that collects all items from a Generatable into a collection.

This is useful for converting a generator/stream of items into a single collected result. The collection type must implement Default and Extend.

§Example

use computation_process::{Generator, GeneratorStep, Completable, Computable, Collector, Stateful, Generatable};

struct RangeStep;

impl GeneratorStep<u32, u32, u32> for RangeStep {
    fn step(max: &u32, current: &mut u32) -> Completable<Option<u32>> {
        *current += 1;
        if *current <= *max {
            Ok(Some(*current))
        } else {
            Ok(None)
        }
    }
}

let generator = Generator::<u32, u32, u32, RangeStep>::from_parts(3, 0);
let mut collector: Collector<u32, Vec<u32>> = generator.dyn_generatable().into();
let result = collector.compute().unwrap();
assert_eq!(result, vec![1, 2, 3]);

Implementations§

Source§

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

Source

pub fn new(generator: G) -> Self

Create a new collector for the given generator.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Collector<ITEM, COLLECTION, G>

Returns a duplicate 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<ITEM, COLLECTION, G> Computable<COLLECTION> for Collector<ITEM, COLLECTION, G>
where COLLECTION: Default + Extend<ITEM>, G: Generatable<ITEM>,

Source§

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

Try to advance this computation, returning a value once the computation is done.
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. Read more
Source§

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

Advance this computation until completion, skipping over all suspended states. Read more
Source§

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

Utility method to convert this Computable to a dynamic type.
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ITEM, COLLECTION: Default + Extend<ITEM>> From<Box<dyn Generatable<ITEM, Item = Result<ITEM, Cancelled>>>> for Collector<ITEM, COLLECTION, DynGeneratable<ITEM>>

Source§

fn from(value: DynGeneratable<ITEM>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn eq(&self, other: &Collector<ITEM, COLLECTION, G>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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

Auto Trait Implementations§

§

impl<ITEM, COLLECTION, G> Freeze for Collector<ITEM, COLLECTION, G>
where G: Freeze, COLLECTION: Freeze,

§

impl<ITEM, COLLECTION, G> RefUnwindSafe for Collector<ITEM, COLLECTION, G>
where G: RefUnwindSafe, COLLECTION: RefUnwindSafe, ITEM: RefUnwindSafe,

§

impl<ITEM, COLLECTION, G> Send for Collector<ITEM, COLLECTION, G>
where G: Send, COLLECTION: Send, ITEM: Send,

§

impl<ITEM, COLLECTION, G> Sync for Collector<ITEM, COLLECTION, G>
where G: Sync, COLLECTION: Sync, ITEM: Sync,

§

impl<ITEM, COLLECTION, G> Unpin for Collector<ITEM, COLLECTION, G>
where G: Unpin, COLLECTION: Unpin, ITEM: Unpin,

§

impl<ITEM, COLLECTION, G> UnwindSafe for Collector<ITEM, COLLECTION, G>
where G: UnwindSafe, COLLECTION: UnwindSafe, ITEM: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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,

Source§

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

Source§

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

Source§

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.