pub struct Collector<ITEM, COLLECTION, G = DynGeneratable<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§
Trait Implementations§
Source§impl<ITEM, COLLECTION, G> Computable<COLLECTION> for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> Computable<COLLECTION> for Collector<ITEM, COLLECTION, G>
Source§fn try_compute(&mut self) -> Completable<COLLECTION>
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>
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>
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,
fn dyn_computable(self) -> DynComputable<T>where
Self: Sized + 'static,
Utility method to convert this
Computable to a dynamic type.Source§impl<'de, ITEM, COLLECTION, G> Deserialize<'de> for Collector<ITEM, COLLECTION, G>where
COLLECTION: Default + Extend<ITEM> + Serialize + for<'a> Deserialize<'a>,
G: Generatable<ITEM> + Serialize + for<'a> Deserialize<'a>,
impl<'de, ITEM, COLLECTION, G> Deserialize<'de> for Collector<ITEM, COLLECTION, G>where
COLLECTION: Default + Extend<ITEM> + Serialize + for<'a> Deserialize<'a>,
G: Generatable<ITEM> + Serialize + for<'a> Deserialize<'a>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<ITEM, COLLECTION: Default + Extend<ITEM>> From<Box<dyn Generatable<ITEM, Item = Result<ITEM, Cancelled>>>> for Collector<ITEM, COLLECTION, DynGeneratable<ITEM>>
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
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>
impl<ITEM: PartialEq, COLLECTION, G> PartialEq for Collector<ITEM, COLLECTION, G>
Source§impl<ITEM, COLLECTION, G> Serialize for Collector<ITEM, COLLECTION, G>where
COLLECTION: Default + Extend<ITEM> + Serialize + for<'a> Deserialize<'a>,
G: Generatable<ITEM> + Serialize + for<'a> Deserialize<'a>,
impl<ITEM, COLLECTION, G> Serialize for Collector<ITEM, COLLECTION, G>where
COLLECTION: Default + Extend<ITEM> + Serialize + for<'a> Deserialize<'a>,
G: Generatable<ITEM> + Serialize + for<'a> Deserialize<'a>,
impl<ITEM: Eq, COLLECTION, G> Eq for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> StructuralPartialEq for Collector<ITEM, COLLECTION, G>
Auto Trait Implementations§
impl<ITEM, COLLECTION, G> Freeze for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> RefUnwindSafe for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> Send for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> Sync for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> Unpin for Collector<ITEM, COLLECTION, G>
impl<ITEM, COLLECTION, G> UnwindSafe for Collector<ITEM, COLLECTION, G>
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