Vector remove method in the language?

Hello, Is there something like this in the language?

//! Remove an element from a vector, not caring about order

pub fn remove_unordered<T>(avec: &mut Vec<T>, inx: usize) {
    assert!(inx < avec.len());
    let last_item = avec.pop().unwrap();

    if inx < avec.len() {
        avec[inx] = last_item;
    }
}

It's called swap_remove. The standard library version also returns the removed value.

2 Likes

Thanks!

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.