pub trait ConcurrentDrainableOverSlice {
type Item;
type DrainingIter<'a>: ConcurrentIter<Item = Self::Item>
where Self: 'a;
// Required method
fn con_drain<R>(&mut self, range: R) -> Self::DrainingIter<'_>
where R: RangeBounds<usize>;
}
Expand description
A type which can create a concurrent draining iterator over any of its sub-slices.
- Created draining iterator yields all elements of the slice defined by the
range
, - Further, the slice is removed from the original collection.
If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
If the complete range is provided (..
or 0..self.len()
), self will remain empty.
§Examples
use orx_concurrent_iter::*;
let mut v = vec![1, 2, 3];
let u: Vec<_> = v.con_drain(1..).item_puller().collect();
assert_eq!(v, &[1]);
assert_eq!(u, &[2, 3]);
Required Associated Types§
Sourcetype DrainingIter<'a>: ConcurrentIter<Item = Self::Item>
where
Self: 'a
type DrainingIter<'a>: ConcurrentIter<Item = Self::Item> where Self: 'a
Type of the concurrent draining iterator created by con_drain
method.
Required Methods§
Sourcefn con_drain<R>(&mut self, range: R) -> Self::DrainingIter<'_>where
R: RangeBounds<usize>,
fn con_drain<R>(&mut self, range: R) -> Self::DrainingIter<'_>where
R: RangeBounds<usize>,
Creates a concurrent draining iterators such that:
- the iterator yields all elements of the slice defined by the
range
, - this slice will be removed from the original collection (
self
).
If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
If the complete range is provided (..
or 0..self.len()
), self will remain empty.
§Panics:
- if the starting point of the
range
is greater than the ending point; or - if the ending point of the
range
is greater thanvec.len()
.
§Leaking
If the returned iterator goes out of scope without being dropped (due to mem::forget, for example),
self
may have lost and leaked elements arbitrarily, including elements outside the range.
§Examples
use orx_concurrent_iter::*;
let mut v = vec![1, 2, 3];
let u: Vec<_> = v.con_drain(1..).item_puller().collect();
assert_eq!(v, &[1]);
assert_eq!(u, &[2, 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.