Answers for "rust filling a vector"

0

rust filling a vector

// Several equivalent examples
fn arr(n: usize) -> Vec<u32> {
    (0 .. n as u32).collect()
}

fn arr(n: usize) -> Vec<u32> {
    let vec_n: Vec<u32> = (0..n as u32).collect();
    vec_n
}

fn arr(n: usize) -> Vec<u32> {
    let mut vec_n: Vec<u32> = Vec::new();
    for x in 0..n {
        vec_n.push(x as u32);
    }
    res
}
Posted by: Guest on February-24-2021

Browse Popular Code Answers by Language