Can a RC move location behind my back?

This is a followup to Hash based on address (not value) of Rc

let x : Rc<...>

is there any guarantee that &*x remains constant ?

Intuitively, I want to say "yes" ... however, if that was the case, why does 'pin' exist for rc? Rc in std::rc - Rust

The data it points to will not move (the pointer handle itself can move).

Pin exists to prevent you from mem::swaping it with something or from taking the data out with try_unwrap.


In practice, Rc::make_mut and Rc::get_mut (EDIT: and try_unwrap) are the main reason why Rc<Pointee> and Pin<Rc<Pointee>> are not equivalent (those methods may "move location"). Otherwise, they are equivalent API-wise, since they both Deref<Target = Pointee>.

Also, see this thread


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.