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§
Sourcetype Iter: ConcurrentIter<Item = Self::Item>
type Iter: ConcurrentIter<Item = Self::Item>
Type of the concurrent iterator that this type can be converted into.
Required Methods§
Sourcefn con_iter(&self) -> Self::Iter
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);
}