title: What is the idiomatic way to pop the last N elements in a mutable Vec?
body: <p>I am contributing Rust code to RosettaCode to both learn Rust and contribute to the Rust community at the same time. What is the best idiomatic way to pop the last <em>n</em> elements in a mutable <code>Vec</code>?</p>
  
  <p>Here's roughly what I have written but I'm wanting to see if there's a better way: </p>
  
  <pre><code>fn main() {
      let mut nums: Vec&lt;u32&gt; = Vec::new();
      nums.push(1);
      nums.push(2);
      nums.push(3);
      nums.push(4);
      nums.push(5);
  
      let n = 2;
      for _ in 0..n {
          nums.pop();
      }
  
      for e in nums {
          println!("{}", e)
      }
  }
  </code></pre>
  
  <p>(<a href="https://play.rust-lang.org/?gist=4961b011516314597f63ebbb9aa3abbe&amp;version=stable&amp;backtrace=0" rel="noreferrer">Playground link</a>)</p>