pub trait ScanMut<T> {
// Required methods
fn multi_insert<I>(&mut self, iter: I)
where I: IntoIterator<Item = (usize, T)>,
I::IntoIter: ExactSizeIterator;
fn multi_remove<I, F>(&mut self, iter: I, sink: F)
where I: IntoIterator<Item = usize>,
F: FnMut(T);
fn insert_all<I>(&mut self, index: usize, items: I)
where I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator + DoubleEndedIterator;
fn insert_all_rev<I>(&mut self, index: usize, items: I)
where I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator;
}
Expand description
Multiple insert/remove functions
Required Methods§
Sourcefn multi_insert<I>(&mut self, iter: I)
fn multi_insert<I>(&mut self, iter: I)
Insert multiple elements at specific indices in O(n)
time.
Indices must be in monotonically non-increasing order (i.e. the next index must be smaller than or equal to the previous index).
§Example
use scanmut::ScanMut;
let mut v = vec![1, 2, 3, 4, 5];
v.multi_insert([(3, 8), (3, 7), (0, 6)].iter().cloned());
assert_eq!(v, vec![6, 1, 2, 3, 7, 8, 4, 5]);
§Panics
Panics if
- The indices are not monotonically non-increasing.
- An index is out of bounds.
Sourcefn multi_remove<I, F>(&mut self, iter: I, sink: F)
fn multi_remove<I, F>(&mut self, iter: I, sink: F)
Remove multiple elements by index and calls a sink function with the removed element.
Indices must be in monotonically increasing order (i.e. the next index must be more than the previous index).
§Example
use scanmut::ScanMut;
let mut v = vec![1, 2, 3, 4, 5];
v.multi_remove([0, 3].iter().cloned(), drop);
assert_eq!(v, vec![2, 3, 5]);
§Panics
Panics if
- The indices are not monotonically increasing.
- An index is out of bounds.
Sourcefn insert_all<I>(&mut self, index: usize, items: I)
fn insert_all<I>(&mut self, index: usize, items: I)
Inserts items from an iterator at the given index.
§Panics
Panics if
- The range
index..(index + items.len())
is out of bounds for thisVec
. - The iterator is shorter or longer than the reported length.
Sourcefn insert_all_rev<I>(&mut self, index: usize, items: I)
fn insert_all_rev<I>(&mut self, index: usize, items: I)
Inserts items in reverse from an iterator at the given index.
§Panics
Panics if
- The range
index..(index + items.len())
is out of bounds for thisVec
. - The iterator is shorter or longer than the reported length.
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.