p3_maybe_rayon::prelude

Trait ParallelDrainRange

Source
pub trait ParallelDrainRange<Idx = usize> {
    type Iter: ParallelIterator<Item = Self::Item>;
    type Item: Send;

    // Required method
    fn par_drain<R>(self, range: R) -> Self::Iter
       where R: RangeBounds<Idx>;
}
Expand description

ParallelDrainRange creates a parallel iterator that moves a range of items from a collection while retaining the original capacity.

Types which are not indexable may implement ParallelDrainFull instead.

Required Associated Types§

Source

type Iter: ParallelIterator<Item = Self::Item>

The draining parallel iterator type that will be created.

Source

type Item: Send

The type of item that the parallel iterator will produce. This is usually the same as IntoParallelIterator::Item.

Required Methods§

Source

fn par_drain<R>(self, range: R) -> Self::Iter
where R: RangeBounds<Idx>,

Returns a draining parallel iterator over a range of the collection.

When the iterator is dropped, all items in the range are removed, even if the iterator was not fully consumed. If the iterator is leaked, for example using std::mem::forget, it is unspecified how many items are removed.

§Examples
use rayon::prelude::*;

let squares: Vec<i32> = (0..10).map(|x| x * x).collect();

println!("RangeFull");
let mut vec = squares.clone();
assert!(vec.par_drain(..)
           .eq(squares.par_iter().copied()));
assert!(vec.is_empty());
assert!(vec.capacity() >= squares.len());

println!("RangeFrom");
let mut vec = squares.clone();
assert!(vec.par_drain(5..)
           .eq(squares[5..].par_iter().copied()));
assert_eq!(&vec[..], &squares[..5]);
assert!(vec.capacity() >= squares.len());

println!("RangeTo");
let mut vec = squares.clone();
assert!(vec.par_drain(..5)
           .eq(squares[..5].par_iter().copied()));
assert_eq!(&vec[..], &squares[5..]);
assert!(vec.capacity() >= squares.len());

println!("RangeToInclusive");
let mut vec = squares.clone();
assert!(vec.par_drain(..=5)
           .eq(squares[..=5].par_iter().copied()));
assert_eq!(&vec[..], &squares[6..]);
assert!(vec.capacity() >= squares.len());

println!("Range");
let mut vec = squares.clone();
assert!(vec.par_drain(3..7)
           .eq(squares[3..7].par_iter().copied()));
assert_eq!(&vec[..3], &squares[..3]);
assert_eq!(&vec[3..], &squares[7..]);
assert!(vec.capacity() >= squares.len());

println!("RangeInclusive");
let mut vec = squares.clone();
assert!(vec.par_drain(3..=7)
           .eq(squares[3..=7].par_iter().copied()));
assert_eq!(&vec[..3], &squares[..3]);
assert_eq!(&vec[3..], &squares[8..]);
assert!(vec.capacity() >= squares.len());

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.

Implementations on Foreign Types§

Source§

impl<'a> ParallelDrainRange for &'a mut String

Source§

type Iter = Drain<'a>

Source§

type Item = char

Source§

fn par_drain<R>(self, range: R) -> <&'a mut String as ParallelDrainRange>::Iter
where R: RangeBounds<usize>,

Source§

impl<'a, T> ParallelDrainRange for &'a mut VecDeque<T>
where T: Send,

Source§

type Iter = Drain<'a, T>

Source§

type Item = T

Source§

fn par_drain<R>( self, range: R, ) -> <&'a mut VecDeque<T> as ParallelDrainRange>::Iter
where R: RangeBounds<usize>,

Source§

impl<'data, T> ParallelDrainRange for &'data mut Vec<T>
where T: Send,

Source§

type Iter = Drain<'data, T>

Source§

type Item = T

Source§

fn par_drain<R>( self, range: R, ) -> <&'data mut Vec<T> as ParallelDrainRange>::Iter
where R: RangeBounds<usize>,

Implementors§