ParOption

pub struct ParOption<F, T, R = RunnerWithPool<SequentialPool>>
where R: ParallelRunner, F: ParIterResult<R, Item = T, Err = ()>,
{ /* private fields */ }
Expand description

A parallel iterator for which the computation either completely succeeds, or fails and early exits with None.

Trait Implementations§

Source§

impl<F, T, R> ParIterOption<R> for ParOption<F, T, R>
where R: ParallelRunner, F: ParIterResult<R, Item = T, Err = ()>,

Source§

type Item = T

Type of the success element, to be received as the Some variant iff the entire computation succeeds.
Source§

fn num_threads(self, num_threads: impl Into<NumThreads>) -> ParOption<F, T, R>

Sets the number of threads to be used in the parallel execution. Integers can be used as the argument with the following mapping: Read more
Source§

fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> ParOption<F, T, R>

Sets the number of elements to be pulled from the concurrent iterator during the parallel execution. When integers are used as argument, the following mapping applies: Read more
Source§

fn iteration_order(self, order: IterationOrder) -> ParOption<F, T, R>

Sets the iteration order of the parallel computation. Read more
Source§

fn with_runner<Q>( self, orchestrator: Q, ) -> impl ParIterOption<Q, Item = <ParOption<F, T, R> as ParIterOption<R>>::Item>
where Q: ParallelRunner,

Rather than the DefaultRunner, uses the parallel runner Q which implements ParallelRunner. Read more
Source§

fn map<Out, Map>(self, map: Map) -> impl ParIterOption<R, Item = Out>
where Map: Fn(<ParOption<F, T, R> as ParIterOption<R>>::Item) -> Out + Sync + Clone, Out: Send,

Takes a closure map and creates a parallel iterator which calls that closure on each element. Read more
Source§

fn filter<Filter>( self, filter: Filter, ) -> impl ParIterOption<R, Item = <ParOption<F, T, R> as ParIterOption<R>>::Item>
where ParOption<F, T, R>: Sized, Filter: Fn(&<ParOption<F, T, R> as ParIterOption<R>>::Item) -> bool + Sync + Clone, <ParOption<F, T, R> as ParIterOption<R>>::Item: Send,

Creates an iterator which uses a closure filter to determine if an element should be yielded. Read more
Source§

fn flat_map<IOut, FlatMap>( self, flat_map: FlatMap, ) -> impl ParIterOption<R, Item = <IOut as IntoIterator>::Item>
where ParOption<F, T, R>: Sized, IOut: IntoIterator, <IOut as IntoIterator>::Item: Send, FlatMap: Fn(<ParOption<F, T, R> as ParIterOption<R>>::Item) -> IOut + Sync + Clone,

Creates an iterator that works like map, but flattens nested structure. Read more
Source§

fn filter_map<Out, FilterMap>( self, filter_map: FilterMap, ) -> impl ParIterOption<R, Item = Out>
where ParOption<F, T, R>: Sized, FilterMap: Fn(<ParOption<F, T, R> as ParIterOption<R>>::Item) -> Option<Out> + Sync + Clone, Out: Send,

Creates an iterator that both filters and maps. Read more
Source§

fn inspect<Operation>( self, operation: Operation, ) -> impl ParIterOption<R, Item = <ParOption<F, T, R> as ParIterOption<R>>::Item>
where ParOption<F, T, R>: Sized, Operation: Fn(&<ParOption<F, T, R> as ParIterOption<R>>::Item) + Sync + Clone, <ParOption<F, T, R> as ParIterOption<R>>::Item: Send,

Does something with each successful element of an iterator, passing the value on, provided that all elements are of Some variant; short-circuits and returns None otherwise. Read more
Source§

fn collect_into<C>(self, output: C) -> Option<C>
where <ParOption<F, T, R> as ParIterOption<R>>::Item: Send, C: ParCollectInto<<ParOption<F, T, R> as ParIterOption<R>>::Item>,

Collects all the items from an iterator into a collection iff all elements are of Some variant. Early exits and returns None if any of the elements is None. Read more
Source§

fn collect<C>(self) -> Option<C>
where <ParOption<F, T, R> as ParIterOption<R>>::Item: Send, C: ParCollectInto<<ParOption<F, T, R> as ParIterOption<R>>::Item>,

Transforms an iterator into a collection iff all elements are of Ok variant. Early exits and returns the error if any of the elements is an Err. Read more
Source§

fn reduce<Reduce>( self, reduce: Reduce, ) -> Option<Option<<ParOption<F, T, R> as ParIterOption<R>>::Item>>
where <ParOption<F, T, R> as ParIterOption<R>>::Item: Send, Reduce: Fn(<ParOption<F, T, R> as ParIterOption<R>>::Item, <ParOption<F, T, R> as ParIterOption<R>>::Item) -> <ParOption<F, T, R> as ParIterOption<R>>::Item + Sync,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Early exits and returns None if any of the elements is None. Read more
Source§

fn first(self) -> Option<Option<<ParOption<F, T, R> as ParIterOption<R>>::Item>>
where <ParOption<F, T, R> as ParIterOption<R>>::Item: Send,

Returns the first (or any) element of the iterator. If the iterator is empty, Some(None) is returned. Early exits and returns None if a None element is observed first. Read more
Source§

fn with_pool<P>( self, pool: P, ) -> impl ParIterOption<RunnerWithPool<P, <R as ParallelRunner>::Executor>, Item = Self::Item>
where P: ParThreadPool, Self: Sized,

Rather than DefaultPool, uses the parallel runner with the given pool implementing ParThreadPool. Read more
Source§

fn all<Predicate>(self, predicate: Predicate) -> Option<bool>
where Self: Sized, Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Tests if every element of the iterator matches a predicate. Early exits and returns None if any of the elements is None. Read more
Source§

fn any<Predicate>(self, predicate: Predicate) -> Option<bool>
where Self: Sized, Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Tests if any element of the iterator matches a predicate. Early exits and returns None if any of the elements is None. Read more
Source§

fn count(self) -> Option<usize>
where Self: Sized,

Consumes the iterator, counting the number of iterations and returning it. Early exits and returns None if any of the elements is None. Read more
Source§

fn for_each<Operation>(self, operation: Operation) -> Option<()>
where Self: Sized, Operation: Fn(Self::Item) + Sync,

Calls a closure on each element of an iterator, and returns Ok(()) if all elements succeed. Early exits and returns None if any of the elements is None. Read more
Source§

fn max(self) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Ord + Send,

Returns Some of maximum element of an iterator if all elements succeed. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn max_by<Compare>(self, compare: Compare) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Send, Compare: Fn(&Self::Item, &Self::Item) -> Ordering + Sync,

Returns the element that gives the maximum value with respect to the specified compare function. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn max_by_key<Key, GetKey>(self, key: GetKey) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Send, Key: Ord, GetKey: Fn(&Self::Item) -> Key + Sync,

Returns the element that gives the maximum value from the specified function. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn min(self) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Ord + Send,

Returns Some of minimum element of an iterator if all elements succeed. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn min_by<Compare>(self, compare: Compare) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Send, Compare: Fn(&Self::Item, &Self::Item) -> Ordering + Sync,

Returns the element that gives the minimum value with respect to the specified compare function. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn min_by_key<Key, GetKey>(self, get_key: GetKey) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Send, Key: Ord, GetKey: Fn(&Self::Item) -> Key + Sync,

Returns the element that gives the minimum value from the specified function. If the iterator is empty, Some(None) is returned. Early exits and returns None if any of the elements is None. Read more
Source§

fn sum<Out>(self) -> Option<Out>
where Self: Sized, Self::Item: Sum<Out>, Out: Send,

Sums the elements of an iterator. Early exits and returns None if any of the elements is None. Read more
Source§

fn find<Predicate>(self, predicate: Predicate) -> Option<Option<Self::Item>>
where Self: Sized, Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Returns the first (or any) element of the iterator that satisfies the predicate. If the iterator is empty, Some(None) is returned. Early exits and returns None if a None element is observed first. Read more

Auto Trait Implementations§

§

impl<F, T, R> Freeze for ParOption<F, T, R>
where F: Freeze,

§

impl<F, T, R> RefUnwindSafe for ParOption<F, T, R>

§

impl<F, T, R> Send for ParOption<F, T, R>
where F: Send, T: Send, R: Send,

§

impl<F, T, R> Sync for ParOption<F, T, R>
where F: Sync, T: Sync, R: Sync,

§

impl<F, T, R> Unpin for ParOption<F, T, R>
where F: Unpin, T: Unpin, R: Unpin,

§

impl<F, T, R> UnwindSafe for ParOption<F, T, R>
where F: UnwindSafe, T: UnwindSafe, R: 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> 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> SoM<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

fn get_mut(&mut self) -> &mut T

Returns a mutable reference to self.
Source§

impl<T> SoR<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
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.