3 ms·
How do you get back something owned by something else?
by i_feel_great 8y ago
How do you get back something owned by something else?
- Munksgaard 8y agoYou don't, unless they pass it to you (as a return value or function argument).
- alrz 8y agoOr if the borrow doesn't outlive the source e.g. if a local goes out of scope.
- i_feel_great 8y agoI don't see that big a deal. In a language, say Ada, I would pass in an "IN" parameter, which cannot be altered in a procedure (and by default in a function). In other languages I would keep the scope/lifetime extremely small, and just not mutate or leak memory. This is just plain ol' good programming practice IMHO. Is there another more compelling use case. In concurrent applications perhaps?
- oconnor663 8y agoYes, being able to pass ownership of a Vec to another thread is important, because otherwise the two threads have to coordinate over when to call its destructor.
- twic 8y agoReturn it from a method, or store it into a field of an object you already own.