let mut a = vec!["1".to_string(), "2".to_string(), "3".to_string()];
let r = &mut a;
let j = r[0];
Below is the error observed.
error[E0507]: cannot move out of index of `Vec<String>`
--> src\main.rs:4:13
|
4 | let j = r[0];
| ^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
|
help: consider borrowing here
|
4 | let j = &r[0];
| +
Although, the same works if Vec has elements with Copy type.