Error "cannot move out of index of" in Rust: what does it mean and how to fix it?
Hi! I started learning Rust and encountered an unclear error when working with a vector. I have a `User` struct, and I'm trying to extract an element from the vector by index to pass it to a function that takes ownership. Here's my code:
```rust
struct User {
name: String,
age: u32,
}
fn process_user(user: User) {
println!("Processing user: {}", user.name);
}
fn main() {
let mut users = vec![
User { name: "Alice".to_string(), age: 30 },
User { name: "Bob".to_string(), age: 25 },
];
let first_user = users[0]; // Error: cannot move out of index of `Vec`
process_user(first_user);
}
```
The compiler gives: `error[E0507]: cannot move out of index of 'Vec'`. I understand that Rust strictly controls ownership, but