title: How do I collect the values of a HashMap into a vector?
body: <p>I can not find a way to collect the values of a <code>HashMap</code> into a <code>Vec</code> in the documentation. I have <code>score_table: HashMap&lt;Id, Score&gt;</code> and I want to get all the <code>Score</code>s into <code>all_scores: Vec&lt;Score&gt;</code>.</p>
  
  <p>I was tempted to use the <code>values</code> method (<code>all_scores = score_table.values()</code>), but it does not work since values is not a <code>Vec</code>.</p>
  
  <p>I know that <code>Values</code> implements the <code>ExactSizeIterator</code> trait, but I do not know how to collect all values of an iterator into a vector without manually writing a for loop and pushing the values in the vector one after one.</p>
  
  <p>I also tried to <code>use std::iter::FromIterator;</code> but ended with something like:</p>
  
  <pre><code>all_scores = Vec::from_iter(score_table.values());
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>expected type `std::vec::Vec&lt;Score&gt;`
     found type `std::vec::Vec&lt;&amp;Score&gt;`
  </code></pre>
  
  <p>Thanks to <a href="https://stackoverflow.com/questions/52093493/hash-map-macro-refuses-to-type-check-failing-with-a-misleading-and-seemingly-b">Hash map macro refuses to type-check, failing with a misleading (and seemingly buggy) error message?</a>, I changed it to:</p>
  
  <pre><code>all_scores = Vec::from_iter(score_table.values().cloned());
  </code></pre>
  
  <p>and it does not produce errors to <code>cargo check</code>.</p>
  
  <p>Is this a good way to do it? </p>