pub fn insert_and_shift<T: Copy>(list: &mut Vec<T>, index: usize, element: T)
Expand description

Insert element at index preserving length.

Arguments

  • list - A vec to be shifted down
  • index - The index at which to insert element
  • element - The element to insert at index

Examples

let mut to_shift = vec![0, 1, 2, 3, 4];
insert_and_shift(&mut to_shift, 2, 11);

assert_eq!(to_shift, vec![0, 1, 11, 2, 3]);