How to append values into existed Vec with iterator I have a Vec with value default [0], and then I want to append into the vec with an iterator which is read from stdin, now my code is not performant since I use an insert to shift all the values behind index 0, how to improve this code with rusty style?
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec&lt;String&gt;,
}
impl Scanner {
    fn next&lt;T: std::str::FromStr&gt;(&amp;mut self) -&gt; T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect(&quot;Failed parse&quot;);
            }
            let mut input = String::new();
            stdin().read_line(&amp;mut input).expect(&quot;Failed read&quot;);
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}


fn main() {
    let mut scan = Scanner::default();

    let n: usize = scan.next();
    // How to improve these lines?
    let mut arr = (0..n).map(|i| scan.next()).collect();
    arr.insert(0, 0);
}


Playground link
I have got an answer with chain
fn main() {
    let mut scan = Scanner::default();
    let n: usize = scan.next();
    let mut arr = vec![0];
    let mut arr: Vec&lt;i32&gt; = arr.into_iter().chain((0..n).map(|i| scan.next())).collect();
    println!(&quot;{:?}&quot;, arr);
}