How can I take an item from a Vec in Rust?
问题 I'm looking for a method that consumes a Vec and returns one element, without the overhead of restoring Vec 's invariants the way remove and swap_remove do: fn take<T>(vec: Vec<T>, index: usize) -> Option<T> However, I can't find such a method. Am I missing something? Is this actually unsafe or impossible? This is a different question from Built in *safe* way to move out of Vec<T>? There the goal was a remove method that didn't panic on out of bounds access and returned a Result . I'm looking