title: How do I convert a HashSet of Strings into a Vector?
body: <p>I'm trying to convert a <code>HashSet&lt;String&gt;</code> into a sorted vector that can then be <code>join</code>ed with commas:</p>
  
  <pre><code>use std::collections::HashSet;
  
  fn main() {
      let mut hs = HashSet::&lt;String&gt;::new();
      hs.insert(String::from("fee"));
      hs.insert(String::from("fie"));
      hs.insert(String::from("foo"));
      hs.insert(String::from("fum"));
  
      let mut v: Vec&lt;&amp;String&gt; = hs.iter().collect();
      v.sort();
  
      println!("{}", v.join(", "));
  }
  </code></pre>
  
  <p>This will not compile:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0599]: no method named `join` found for struct `std::vec::Vec&lt;&amp;std::string::String&gt;` in the current scope
    --&gt; src/main.rs:13:22
     |
  13 |     println!("{}", v.join(", "));
     |                      ^^^^ method not found in `std::vec::Vec&lt;&amp;std::string::String&gt;`
  </code></pre>
  
  <p>I understand why I can't join the <code>Vec&lt;&amp;String&gt;</code>, but how can I convert the <code>HashSet</code> to a <code>Vec&lt;String&gt;</code> instead, so it can be joined?</p>
  
  <p>The examples given in <a href="https://stackoverflow.com/q/36941851/96233">What&#39;s an idiomatic way to print an iterator separated by spaces in Rust?</a> do not seem to apply because the iterator for <code>Args</code> returns <code>String</code> values, unlike the iterator for <code>HashSet</code> which returns <code>&amp;String</code>.</p>