Trait ConcurrentIterable

Source
pub trait ConcurrentIterable {
    type Item: Send + Sync;
    type Iter: ConcurrentIter<Item = Self::Item>;

    // Required method
    fn con_iter(&self) -> Self::Iter;
}
Expand description

ConcurrentIterable types are those from which concurrent iterators can be created multiple times using the con_iter method, since this method call does not consume the source.

This trait can be considered as the concurrent counterpart of the Iterable trait.

§Examples

use orx_concurrent_iter::*;

let vec = vec![1, 2]; // Vec<T>: ConcurrentIterable<Item = &T>
for _ in 0..5 {
    let con_iter = vec.con_iter();
    assert_eq!(con_iter.next(), Some(&1));
    assert_eq!(con_iter.next(), Some(&2));
    assert_eq!(con_iter.next(), None);
}

let slice = vec.as_slice(); // &[T]: ConcurrentIterable<Item = &T>
for _ in 0..5 {
    let con_iter = slice.con_iter();
    assert_eq!(con_iter.next(), Some(&1));
    assert_eq!(con_iter.next(), Some(&2));
    assert_eq!(con_iter.next(), None);
}

let range = 11..13; // Range<T>: ConcurrentIterable<Item = T>
for _ in 0..5 {
    let con_iter = range.con_iter();
    assert_eq!(con_iter.next(), Some(11));
    assert_eq!(con_iter.next(), Some(12));
    assert_eq!(con_iter.next(), None);
}

Required Associated Types§

Source

type Item: Send + Sync

Type of the element that the concurrent iterator yields.

Source

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

Type of the concurrent iterator that this type can be converted into.

Required Methods§

Source

fn con_iter(&self) -> Self::Iter

ConcurrentIterable types are those from which concurrent iterators can be created multiple times using the con_iter method, since this method call does not consume the source.

This trait can be considered as the concurrent counterpart of the Iterable trait.

§Examples
use orx_concurrent_iter::*;

let vec = vec![1, 2]; // Vec<T>: ConcurrentIterable<Item = &T>
for _ in 0..5 {
    let con_iter = vec.con_iter();
    assert_eq!(con_iter.next(), Some(&1));
    assert_eq!(con_iter.next(), Some(&2));
    assert_eq!(con_iter.next(), None);
}

let slice = vec.as_slice(); // &[T]: ConcurrentIterable<Item = &T>
for _ in 0..5 {
    let con_iter = slice.con_iter();
    assert_eq!(con_iter.next(), Some(&1));
    assert_eq!(con_iter.next(), Some(&2));
    assert_eq!(con_iter.next(), None);
}

let range = 11..13; // Range<T>: ConcurrentIterable<Item = T>
for _ in 0..5 {
    let con_iter = range.con_iter();
    assert_eq!(con_iter.next(), Some(11));
    assert_eq!(con_iter.next(), Some(12));
    assert_eq!(con_iter.next(), None);
}

Implementations on Foreign Types§

Source§

impl<'a, T> ConcurrentIterable for &'a [T]
where T: Send + Sync,

Source§

type Item = &'a T

Source§

type Iter = ConIterSlice<'a, T>

Source§

fn con_iter(&self) -> Self::Iter

Source§

impl<'a, X> ConcurrentIterable for &'a X

Source§

impl<I> ConcurrentIterable for CloningIterable<I>
where I: Iterator + Clone, I::Item: Send + Sync,

Source§

type Item = <I as Iterator>::Item

Source§

type Iter = ConIterOfIter<I>

Source§

fn con_iter(&self) -> Self::Iter

Source§

impl<T> ConcurrentIterable for Range<T>
where T: Send + Sync + From<usize> + Into<usize>, Range<T>: Default + Clone + ExactSizeIterator<Item = T>,

Source§

type Item = T

Source§

type Iter = ConIterRange<T>

Source§

fn con_iter(&self) -> Self::Iter

Implementors§