I started writing a response in the morning and forgot about it, sorry.
Yes, the short version would be that the vector is a struct that has on the stack(if you don’t allocate it on the heap yourself of course, like putting it in a
Box) the size of the pre-allocated memory(not in bytes but in number of elements that can be stored), it’s length(number of actual elements in the vector) and a pointer to the data that is in the heap.
Of course it’s an implementation detail, but the short version is that it contains that data.
When a structure like the vector is moved, what actually happens is that yes, what was on the stack is taken ownership as you understood(a copy is made of those fields that are on the stack before popping it of the current stack) but the data that is in the heap doesn’t need to be copied, it remains there like nothing happened.
I am not sure I understand the question.
If the vector owns the elements, than it can pop elements out freely and return the element that was popped.
If it is a shared reference(immutable reference), than of course you won’t be able to pop any elements and return them.
You can also
clone() elements, but it is preferred not to make additional copies if you don’t really need this.
Also remember to use references where appropriate. In Rust it’s pretty nice to use references to be efficient and not worry about safety problems that come with references because Rust guarantees you that you won’t make any mistakes related to pointers/references(in safe code).