Answers for "rust remove vector element"

1

remove an element from vector rust

fn main() {

    let mut num = vec![10, 20, 30, 40, 50];

    // remove [2] (30)
    num.remove(2);

    println!("num[0]: {}", num[0]);
    println!("num[1]: {}", num[1]);
    println!("num[2]: {}", num[2]);
    println!("num[3]: {}", num[3]);

}
Posted by: Guest on October-12-2021

Browse Popular Code Answers by Language