[][src]Trait scanmut::ScanMut

pub trait ScanMut<T> {
    pub fn multi_insert<I>(&mut self, iter: I)
    where
        I: IntoIterator<Item = (usize, T)>,
        I::IntoIter: ExactSizeIterator
;
pub fn multi_remove<I, F>(&mut self, iter: I, sink: F)
    where
        I: IntoIterator<Item = usize>,
        F: FnMut(T)
;
pub fn insert_all<I>(&mut self, index: usize, items: I)
    where
        I: IntoIterator<Item = T>,
        I::IntoIter: ExactSizeIterator + DoubleEndedIterator
;
pub fn insert_all_rev<I>(&mut self, index: usize, items: I)
    where
        I: IntoIterator<Item = T>,
        I::IntoIter: ExactSizeIterator
; }

Multiple insert/remove functions

Required methods

pub fn multi_insert<I>(&mut self, iter: I) where
    I: IntoIterator<Item = (usize, T)>,
    I::IntoIter: ExactSizeIterator
[src]

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.

pub fn multi_remove<I, F>(&mut self, iter: I, sink: F) where
    I: IntoIterator<Item = usize>,
    F: FnMut(T), 
[src]

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.

pub fn insert_all<I>(&mut self, index: usize, items: I) where
    I: IntoIterator<Item = T>,
    I::IntoIter: ExactSizeIterator + DoubleEndedIterator
[src]

Inserts items from an iterator at the given index.

Panics

Panics if

  • The range index..(index + items.len()) is out of bounds for this Vec.
  • The iterator is shorter or longer than the reported length.

pub fn insert_all_rev<I>(&mut self, index: usize, items: I) where
    I: IntoIterator<Item = T>,
    I::IntoIter: ExactSizeIterator
[src]

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 this Vec.
  • The iterator is shorter or longer than the reported length.
Loading content...

Implementations on Foreign Types

impl<T> ScanMut<T> for Vec<T>[src]

Loading content...

Implementors

Loading content...