The following Rust code is from the book Programming Rust. I inserted some (hopefully correct?) pointer addresses to be printed in order to check where the objects reside in memory.
fn main() {
struct Person {
name: Option<String>,
birth: i32,
}
let mut composers = Vec::new();
composers.push(Person {
name: Some("Palestrina".to_string()),
birth: 1525,
});
println!("first_elem addr {:p}", &composers[0].name);
let first_name = std::mem::replace(&mut composers[0].name, None);
println!("first_elem addr {:p}", &composers[0].name);
println!("first name addr {:p}", &first_name);
}
Note that the last displayed object address is totally different from the original location where the value Some("Palestrina".to_string()) resided. Given that is true: I think it would be fair to say that a new object was created (whose value equals the former name of composers[0], but it is still in a fresh memory location).
However the terminology that is used in the book claims something different: "the value was moved out of composers[0].name". Now, I always thought a move is precisely not! the creation of a new object, but merely a new owner of the original value (at the same memory location!). However this is not the case. So my question: Do I have an error in the address-displays or is the notion of a "move" defined differently?