title: Passing Vec<String> as IntoIterator<&'a str>
body: <p>I have a function that is supposed to pick random words from a list of words:</p>
  
  <pre><code>pub fn random_words&lt;'a, I, R&gt;(rng: &amp;mut R, n: usize, words: I) -&gt; Vec&lt;&amp;'a str&gt;
  where
      I: IntoIterator&lt;Item = &amp;'a str&gt;,
      R: rand::Rng,
  {
      rand::sample(rng, words.into_iter(), n)
  }
  </code></pre>
  
  <p>Presumably that's a reasonable signature: Since I don't actually need the string itself in the function, working on references is more efficient than taking a full <code>String</code>.</p>
  
  <p>How do I elegantly and efficiently pass a <code>Vec&lt;String&gt;</code> with words that my program reads from a file to this function?  I got as far as this:</p>
  
  <pre><code>extern crate rand;
  
  fn main() {
      let mut rng = rand::thread_rng();
      let wordlist: Vec&lt;String&gt; = vec!["a".to_string(), "b".to_string()];
  
      let words = random_words(&amp;mut rng, 4, wordlist.iter().map(|s| s.as_ref()));
  }
  </code></pre>
  
  <p>Is that the proper way?  Can I write this without explicitly mapping over the list of words to get a reference?</p>