What can owner of an object do?

I'm new to Rust and understanding the ownership model is not very straightforward for me. My question is that, is this true to say that only superiority the owner of an object has compared to others, is that it can drop the object or move it to another owner?

While an object is borrowed, the owner can't move it, can't destroy it, and can't mutate it.

When there are no loans of the object, the owner can move it, can drop it, and can always mutate it (there are no immutable objects in Rust, only loans that can make their target immutable for the duration of the loan, and even that excludes "interior mutability" types).

Non-owners can move objects through &mut references, because there's std::mem::swap. There always has to be some valid object behind a reference, but it doesn't have to be the same object (this is one of the reasons why Pin needs to exist).

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.