I'm learning Rust and I've a question regarding how to pass a reference of a variable to a function and make a cascade call with it.
I'm facing the error indicated in the code below:
struct User {
name: String,
address: String
}
// Argument "user" is intentionally a reference to User struct;
//
fn func1(user: &User) {
println!("func1: {}, {}", user.name, user.address);
// error[E0507]: cannot move out of `*user` which is behind a shared reference
//
func2(*user);
}
// Argument "user" is intentionally an instance of User struct;
//
fn func2(user: User) {
println!("func2: {}, {}", user.name, user.address);
}
fn main() {
let user = User {
name: String::from("George"),
address: String::from("Main Street")
};
func1(&user);
}
Why can't I do that? What am I supposed to do?
I think cloning the User object is not a option. Imagine if instead of this simple structure we have a super structure that could occupy several MBytes?