pub trait ParCompactable: Kind_cdc7cd43dac7585f {
// Required methods
fn par_compact<'a, A: 'a + Send>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>;
fn par_separate<'a, E: 'a + Send, O: 'a + Send>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>);
}Expand description
A type class for data structures that can be compacted and separated in parallel.
ParCompactable is the parallel counterpart to Compactable.
Implementors define par_compact and
par_separate directly: there is no intermediate Vec
conversion imposed by the interface.
§Thread Safety
All par_* functions require Send bounds on element types.
These bounds apply even when the rayon feature is disabled, so that code compiles
identically in both configurations.
Note: The rayon feature must be enabled to use actual parallel execution. Without
it, all par_* functions fall back to equivalent sequential operations.
§Examples
use fp_library::{
brands::VecBrand,
functions::*,
};
let v = vec![Some(1), None, Some(3)];
let result: Vec<i32> = par_compact::<VecBrand, _>(v);
assert_eq!(result, vec![1, 3]);
let v2: Vec<Result<i32, &str>> = vec![Ok(1), Err("e"), Ok(3)];
let (errs, oks): (Vec<&str>, Vec<i32>) = par_separate::<VecBrand, _, _>(v2);
assert_eq!(errs, vec!["e"]);
assert_eq!(oks, vec![1, 3]);Required Methods§
Sourcefn par_compact<'a, A: 'a + Send>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>,
) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
fn par_compact<'a, A: 'a + Send>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, <OptionBrand as Kind_cdc7cd43dac7585f>::Of<'a, A>>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>
Compacts a data structure of Options in parallel, discarding None values and
keeping Some values.
When the rayon feature is enabled, elements are processed across multiple threads.
Otherwise falls back to sequential compaction.
§Type Signature
forall A. Self (Option A) -> Self A
§Type Parameters
'a: The lifetime of the elements.A: The type of the elements in theOption.
§Parameters
fa: The data structure containingOptionvalues.
§Returns
A new data structure containing only the values from the Some variants.
§Examples
use fp_library::{
brands::VecBrand,
classes::par_compactable::ParCompactable,
};
let v = vec![Some(1), None, Some(3)];
let result: Vec<i32> = VecBrand::par_compact(v);
assert_eq!(result, vec![1, 3]);Sourcefn par_separate<'a, E: 'a + Send, O: 'a + Send>(
fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>,
) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)
fn par_separate<'a, E: 'a + Send, O: 'a + Send>( fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, Result<O, E>>, ) -> (<Self as Kind_cdc7cd43dac7585f>::Of<'a, E>, <Self as Kind_cdc7cd43dac7585f>::Of<'a, O>)
Separates a data structure of Results into two data structures in parallel.
When the rayon feature is enabled, elements are processed across multiple threads.
Otherwise falls back to sequential separation.
§Type Signature
forall E O. Self (Result O E) -> (Self E, Self O)
§Type Parameters
'a: The lifetime of the elements.E: The type of the error values.O: The type of the success values.
§Parameters
fa: The data structure containingResultvalues.
§Returns
A pair of data structures: the first containing the Err values, and the second containing the Ok values.
§Examples
use fp_library::{
brands::VecBrand,
classes::par_compactable::ParCompactable,
};
let v: Vec<Result<i32, &str>> = vec![Ok(1), Err("e"), Ok(3)];
let (errs, oks): (Vec<&str>, Vec<i32>) = VecBrand::par_separate(v);
assert_eq!(errs, vec!["e"]);
assert_eq!(oks, vec![1, 3]);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.