I've been looking over the documentation, and so far I haven't seen a built in function to safely move an item out of a Vec
.
Vec::get
exists, but that just borrows. Vec::remove
exists, and while that does move out of the vector, it also panics if the index is out of range. So, I have two questions:
- What is the intended/good way to move an item from a vector?
remove(&mut self, index: usize) -> T
panics if out of range. What might be the reason for panicking? Why isn't it implemented likeremove(&mut self, index: usize) -> Option<T>
?