pub fn insert_in_vec<Data>(
    vec: &mut Vec<Data>,
    pos: usize,
    data: Data,
    default_data: &Data
)where
    Data: Clone,
Expand description

Try setting the value inside the vec at position pos. If the position is not the array, build the array with default value up to pos - 1 and insert data at pos.

Example

use std::vec::Vec;

let mut vec = vec![];
insert_in_vec(&mut vec, 0, 1, &0);
assert_eq!(vec, vec![1]);
insert_in_vec(&mut vec, 3, 9, &0);
assert_eq!(vec, vec![1, 0, 0, 9]);
insert_in_vec(&mut vec, 5, 10, &1);
assert_eq!(vec, vec![1, 0, 0, 9, 1, 10]);
insert_in_vec(&mut vec, 1, 3, &1);
assert_eq!(vec, vec![1, 3, 0, 9, 1, 10]);