pub trait ParUseResult: Sized + ParUseResultCore {
Show 32 methods
// Required methods
fn runner<Q: ParRunner>(
self,
runner: Q,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>;
fn runner_with_diagnostics(
self,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>;
fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self;
fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self;
fn iteration_order(self, collect: IterationOrder) -> Self;
fn map<Q, H>(
self,
h: H,
) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMap<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(&mut Self::Use, Self::Elem) -> Q + Copy + Send;
fn inspect<H>(
self,
h: H,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UInspect<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(&mut Self::Use, &Self::Elem) + Copy + Send;
fn filter<H>(
self,
h: H,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilter<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(&mut Self::Use, &Self::Elem) -> bool + Copy + Send;
fn filter_map<Q, H>(
self,
h: H,
) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilterMap<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(&mut Self::Use, Self::Elem) -> Option<Q> + Copy + Send;
fn flat_map<V, H>(
self,
h: H,
) -> impl ParUseResult<Elem = V::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatMap<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where V: IntoIterator,
H: Fn(&mut Self::Use, Self::Elem) -> V + Copy + Send;
fn flatten(
self,
) -> impl ParUseResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatten<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where Self::Elem: IntoIterator;
fn size_hint(&self) -> (usize, Option<usize>);
fn first(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
Self::Error: Send;
fn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where F: Fn(&mut Self::Use, Self::Elem, Self::Elem) -> Self::Elem + Send + Copy,
Self::Elem: Send,
Self::Error: Send;
fn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
where P: ParExtend<Self::Elem>,
Self::Elem: Send,
Self::Error: Send;
// Provided methods
fn copied<'a, O>(
self,
) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCopied<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParUseResult<Elem = &'a O>,
O: Copy + 'a,
Self::Use: 'a { ... }
fn cloned<'a, O>(
self,
) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCloned<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParUseResult<Elem = &'a O>,
O: Clone + 'a,
Self::Use: 'a { ... }
fn len(&self) -> usize
where Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne> { ... }
fn is_empty(&self) -> bool
where Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne> { ... }
fn collect<P>(self) -> Result<P, Self::Error>
where P: ParExtend<Self::Elem> + Default,
Self::Elem: Send,
Self::Error: Send { ... }
fn all<F>(self, f: F) -> Result<bool, Self::Error>
where Self::Elem: Send,
F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn any<F>(self, f: F) -> Result<bool, Self::Error>
where Self::Elem: Send,
F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn count(self) -> Result<usize, Self::Error>
where Self::Elem: Send,
Self::Error: Send { ... }
fn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
where F: Fn(&mut Self::Use, Self::Elem) + Send + Copy,
Self::Error: Send { ... }
fn max(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Ord + Send,
Self::Error: Send { ... }
fn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync,
Self::Error: Send { ... }
fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
B: Ord,
F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync,
Self::Error: Send { ... }
fn min(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Ord + Send,
Self::Error: Send { ... }
fn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync,
Self::Error: Send { ... }
fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
B: Ord,
F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync,
Self::Error: Send { ... }
fn sum<S>(self) -> Result<S, Self::Error>
where Self::Elem: Sum<S>,
S: Send,
Self::Error: Send { ... }
}Expand description
Fallible parallel iterator with worker-local mutable state.
ParUseResult combines:
- fallible processing (
Result-based short-circuiting), and - mutable worker-local state (
&mut Usepassed to closures).
You can enter this mode from ParResult via
use_new,
use_vec, or
use_slice.
Similar to using ?, this trait keeps pipeline logic focused on successful
values while computation short-circuits to Err(e) when any element fails.
Related traits:
ParResultforResult-fallible pipelines without worker-local state,ParUsefor worker-local state in infallible pipelines.
§Examples
Reusing a per-worker buffer:
use core::fmt::Write;
use orx_parallel::*;
let out: Result<Vec<usize>, _> = ["0", "1", "2", "3", "4", "5", "6", "7"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| String::with_capacity(32))
.map(|buffer, x| {
buffer.clear();
write!(buffer, "{x}").unwrap();
buffer.parse::<usize>().unwrap()
})
.collect();
assert_eq!(out, Ok((0..8).collect::<Vec<_>>()));Using RNG as mutable worker-local state:
use orx_parallel::*;
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
let out: Result<Vec<usize>, _> = ["0", "1", "2", "3", "4", "5", "6", "7"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|thread_idx| ChaCha8Rng::seed_from_u64(100 + thread_idx as u64))
.map(|rng, x| x + rng.random_range(0..10))
.collect();
assert_eq!(out.as_ref().map(Vec::len), Ok(8));Required Methods§
Sourcefn runner<Q: ParRunner>(
self,
runner: Q,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
fn runner<Q: ParRunner>( self, runner: Q, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
Replaces the current parallel runner with runner.
§Examples
use orx_parallel::*;
let par = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ());
let par = par.runner(Runner::fixed());
let out: Result<Vec<_>, _> = par.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn runner_with_diagnostics(
self,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
fn runner_with_diagnostics( self, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
Wraps the current runner with diagnostics-enabled execution.
§Examples
use orx_parallel::*;
let par = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ());
#[cfg(feature = "std")]
let par = par.runner_with_diagnostics();
let out: Result<Vec<_>, _> = par.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn num_threads(self, num_threads: impl Into<NumThreads>) -> Self
fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self
Sets the maximum number of worker threads for this computation.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3", "4", "5"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.num_threads(1)
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4, 5]));Sourcefn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self
fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self
Sets chunk size used when pulling items from the concurrent input.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["0", "1", "2", "3", "4", "5", "6", "7"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.chunk_size(2)
.collect();
assert_eq!(out, Ok((0..8).collect::<Vec<_>>()));Sourcefn iteration_order(self, collect: IterationOrder) -> Self
fn iteration_order(self, collect: IterationOrder) -> Self
Sets iteration-order semantics for order-sensitive operations.
§Examples
use orx_parallel::*;
let ordered = (1..10_000)
.map(|x| x.to_string())
.collect::<Vec<_>>()
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.iteration_order(IterationOrder::Ordered)
.find(|_, x| x % 3421 == 0);
assert_eq!(ordered, Ok(Some(3421)));Sourcefn map<Q, H>(
self,
h: H,
) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMap<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
fn map<Q, H>( self, h: H, ) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMap<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
Maps each successful element with closure h.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.map(|_, x| 2 * x)
.collect();
assert_eq!(out, Ok(vec![2, 4, 6]));Sourcefn inspect<H>(
self,
h: H,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UInspect<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
fn inspect<H>( self, h: H, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UInspect<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
Runs h on each successful element and forwards the item unchanged.
§Examples
use orx_parallel::*;
let mut use_vec = UseVec::new(|_| 0usize);
let out: Result<Vec<_>, _> = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_vec(&mut use_vec)
.inspect(|count, _| *count += 1)
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4]));
assert_eq!(use_vec.into_vec().into_iter().sum::<usize>(), 4);Sourcefn filter<H>(
self,
h: H,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilter<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
fn filter<H>( self, h: H, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilter<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
Keeps successful elements satisfying predicate h.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3", "4", "5", "6"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.filter(|_, x| x % 2 == 1)
.collect();
assert_eq!(out, Ok(vec![1, 3, 5]));Sourcefn filter_map<Q, H>(
self,
h: H,
) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilterMap<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
fn filter_map<Q, H>( self, h: H, ) -> impl ParUseResult<Elem = Q, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilterMap<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
Maps and filters successful elements in one pass.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "x", "5"]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.filter_map(|_, s| s.parse::<usize>().ok())
.collect();
assert_eq!(out, Ok(vec![1, 5]));Sourcefn flat_map<V, H>(
self,
h: H,
) -> impl ParUseResult<Elem = V::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatMap<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
fn flat_map<V, H>( self, h: H, ) -> impl ParUseResult<Elem = V::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatMap<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
Maps each successful element to an iterator and flattens one level.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.flat_map(|_, x| [x, x + 10])
.collect();
assert_eq!(out, Ok(vec![1, 11, 2, 12, 3, 13]));Sourcefn flatten(
self,
) -> impl ParUseResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatten<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>where
Self::Elem: IntoIterator,
fn flatten(
self,
) -> impl ParUseResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatten<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>where
Self::Elem: IntoIterator,
Flattens one level of nested iterables on the success path.
§Examples
use orx_parallel::*;
let nested = vec![vec![1, 2], vec![3, 4]];
let out: Result<Vec<_>, &'static str> = nested
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.flatten()
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4]));Sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns a lower and optional upper bound on the number of successful output items.
The bounds follow the usual Iterator::size_hint convention.
The upper bound includes items that may be removed by filtering or short-circuiting.
§Examples
use orx_parallel::*;
let values = (0..4)
.into_par()
.map(Ok::<_, ()>)
.into_fallible()
.use_new(|_| ())
.filter(|_, x| x % 2 == 0);
assert_eq!(values.size_hint(), (0, Some(4)));Sourcefn first(self) -> Result<Option<Self::Elem>, Self::Error>
fn first(self) -> Result<Option<Self::Elem>, Self::Error>
Returns the first successful item according to iteration order.
Returns:
Err(e)if computation short-circuits due to a failureOk(None)if no successful element existsOk(Some(x))for the first successful element
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.first();
assert_eq!(ok, Ok(Some(1)));
let fail = ["bad", "1", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.first();
assert!(fail.is_err());Sourcefn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Reduces successful items into one value using f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4", "5"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.reduce(|_, a, b| a + b);
assert_eq!(ok, Ok(Some(15)));
let fail = ["1", "x", "3"]
.into_par()
.map(|s| s.parse::<usize>().map_err(|_| "parse"))
.into_fallible()
.use_new(|_| ())
.reduce(|_, a, b| a + b);
assert_eq!(fail, Err("parse"));Sourcefn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
fn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
Collects successful items into dst.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let mut dst = vec![10usize];
let ok = ["0", "1", "2"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.collect_into(&mut dst);
assert_eq!(ok, Ok(()));
assert_eq!(dst, vec![10, 0, 1, 2]);Provided Methods§
Sourcefn copied<'a, O>(
self,
) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCopied<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
fn copied<'a, O>( self, ) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCopied<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
Copies elements of a reference iterator on the success path.
§Examples
use orx_parallel::*;
let data = vec![1, 2, 3];
let out: Result<Vec<_>, &'static str> = data
.par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.copied()
.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn cloned<'a, O>(
self,
) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCloned<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
fn cloned<'a, O>( self, ) -> impl ParUseResult<Elem = O, Error = Self::Error, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCloned<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
Clones elements of a reference iterator on the success path.
§Examples
use orx_parallel::*;
let data = vec!["a".to_string(), "b".to_string()];
let out: Result<Vec<_>, &'static str> = data
.par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.cloned()
.collect();
assert_eq!(out, Ok(vec!["a".to_string(), "b".to_string()]));Sourcefn len(&self) -> usizewhere
Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne>,
fn len(&self) -> usizewhere
Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne>,
Returns the exact number of output items.
Sourcefn is_empty(&self) -> boolwhere
Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne>,
fn is_empty(&self) -> boolwhere
Self::Input: ExactSizeConcurrentIter,
Self: ParUseResult<Size = OneOne>,
Returns true when the parallel iterator has no output items.
Sourcefn collect<P>(self) -> Result<P, Self::Error>
fn collect<P>(self) -> Result<P, Self::Error>
Collects successful items into a new collection.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn all<F>(self, f: F) -> Result<bool, Self::Error>
fn all<F>(self, f: F) -> Result<bool, Self::Error>
Returns Ok(true) if all successful items satisfy f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.all(|_, x| x > &0);
assert_eq!(ok, Ok(true));Sourcefn any<F>(self, f: F) -> Result<bool, Self::Error>
fn any<F>(self, f: F) -> Result<bool, Self::Error>
Returns Ok(true) if any successful item satisfies f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.any(|_, x| x % 2 == 0);
assert_eq!(ok, Ok(true));Sourcefn count(self) -> Result<usize, Self::Error>
fn count(self) -> Result<usize, Self::Error>
Counts successful elements.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.filter(|_, x| x % 3 == 0)
.count();
assert_eq!(ok, Ok(3));Sourcefn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Finds first (ordered) or any (arbitrary) successful item satisfying f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let found = (1..101)
.map(|x| x.to_string())
.collect::<Vec<_>>()
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.find(|_, x| x % 17 == 0);
assert_eq!(found, Ok(Some(17)));Sourcefn for_each<F>(self, f: F) -> Result<(), Self::Error>
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
Executes f for each successful element.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let mut sums = UseVec::new(|_| 0usize);
let result = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_vec(&mut sums)
.for_each(|local, x| *local += x);
assert_eq!(result, Ok(()));
assert_eq!(sums.into_vec().into_iter().sum::<usize>(), 10);Sourcefn max(self) -> Result<Option<Self::Elem>, Self::Error>
fn max(self) -> Result<Option<Self::Elem>, Self::Error>
Returns maximum successful element.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let m = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.max();
assert_eq!(m, Ok(Some(4)));Sourcefn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element considered maximum by comparator f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.max_by(|_, a, b| a.cmp(b));
assert_eq!(x, Ok(Some(5)));Sourcefn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element with maximum key value.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.max_by_key(|_, x| x.abs());
assert_eq!(x, Ok(Some(-10)));Sourcefn min(self) -> Result<Option<Self::Elem>, Self::Error>
fn min(self) -> Result<Option<Self::Elem>, Self::Error>
Returns minimum successful element.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let m = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|_| ())
.min();
assert_eq!(m, Ok(Some(1)));Sourcefn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element considered minimum by comparator f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.min_by(|_, a, b| a.cmp(b));
assert_eq!(x, Ok(Some(-10)));Sourcefn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element with minimum key value.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.use_new(|_| ())
.min_by_key(|_, x| x.abs());
assert_eq!(x, Ok(Some(0)));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".