title: Join iterator of &str
body: <p>How do I convert an <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html" rel="nofollow noreferrer"><code>Iterator</code></a><a href="https://doc.rust-lang.org/std/primitive.str.html" rel="nofollow noreferrer"><code>&lt;&amp;str&gt;</code></a> to a <a href="https://doc.rust-lang.org/std/string/struct.String.html" rel="nofollow noreferrer"><code>String</code></a>, interspersed with a constant string such as <code>&quot;\n&quot;</code>?
  For instance, given:</p>
  <pre><code>let xs = vec![&quot;first&quot;, &quot;second&quot;, &quot;third&quot;];
  let it = xs.iter();
  </code></pre>
  <p>One may produce a string <code>s</code> by <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect" rel="nofollow noreferrer"><code>collect</code></a>ing into a <code>Vec&lt;&amp;str&gt;</code> and <a href="https://doc.rust-lang.org/std/primitive.slice.html#method.join" rel="nofollow noreferrer"><code>join</code></a>ing the result:</p>
  <pre><code>let s = it
      .map(|&amp;x| x)
      .collect::&lt;Vec&lt;&amp;str&gt;&gt;()
      .join(&quot;\n&quot;);
  </code></pre>
  <p>However, <strong>this unnecessarily allocates memory</strong> for a <code>Vec&lt;&amp;str&gt;</code>.</p>
  <p>Is there a more direct method?</p>