Below is a code snippet (playground) that I tried to run:
fn main() {
let a = vec!["hello".to_string(), "world".to_string()];
let b = vec![10, 20, 30];
let c = a[0];
let d = b[0];
println!("{:?}", c);
println!("{:?}", d);
}
The error says that "values can't be moved out of borrowed content":
error[E0507]: cannot move out of borrowed content
--> src/main.rs:5:13
|
5 | let c = a[0];
| ^^^^
| |
| cannot move out of borrowed content
| help: consider borrowing here: `&a[0]`
But I don't see any explicit borrowing being done. Where exactly is the borrowing done? And what is borrowed? And what is the borrowed content mentioned in the error?
This doesn't happen with primitive types like floats, chars etc. Maybe because values are copied rather than being moved, which is possible only in case of primitives (data structures whose values are completely stored in stack rather than in heap).