I have a Vec<f32>
like this:
let mut v: Vec<f32> = Vec::new();
v.push(1.0);
v.push(2.0);
v.push(3.0);
Is there an idiomatic way to replace a portion of the contents with a slice? I have a function like this:
fn replace(&mut v: Vec<f32>, start: usize, vals: &[f32]) {
// ...
}
In this case, I'd like to replace the values in v
with values from vals
, starting from the index start
of v
. If I have the aforementioned Vec
, I'd like to do this:
// Before v contains (1.0, 2.0, 3.0)
replace(&v, 0, &[4.0, 5.0]);
// Now v would contain (4.0, 5.0, 3.0)
I guess this could be done by iterating starting from the start
index, but is there a more idiomatic Rust way of doing this?