With this code, I can update a single value in an array:
fn main() {
let mut values = vec![0; 5];
dbg!(&values);
{
let v = &mut values;
(*v)[2] = 1;
}
dbg!(&values);
}
But, it does not work when update two values at the same time:
fn main() {
let mut values = vec![0; 5];
dbg!(&values);
{
let v = &mut values;
(*v)[2..4] = [1, 1];
}
dbg!(&values);
}
Errors:
error[E0308]: mismatched types
--> src/main.rs:7:22
|
7 | (*v)[2..4] = [1, 1];
| ^^^^^^^^^ expected slice `[{integer}]`, found array `[{integer}; 3]`
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
--> src/main.rs:7:9
|
7 | (*v)[2..4] = [1, 1];
| ^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[{integer}]`
= note: the left-hand-side of an assignment must have a statically known size
error: aborting due to 2 previous errors
How do you update multiple values ?