title: How can I specify an iterator over traits?
body: <p>I've been trying to make a websocket client, but one that has tons of options! I thought of using a builder style since the configuration can be stored in a nice way:</p>
  
  <pre><code>let client = Client::new()
      .options(5)
      .stuff(true)
      // now users can store the config before calling build
      .build();
  </code></pre>
  
  <p>I am having trouble creating a function that takes in a list of strings. Of course I have a few options:</p>
  
  <pre><code>fn strings(self, list: &amp;[&amp;str]) -&gt; Self;
  fn strings(self, list: Vec&lt;String&gt;) -&gt; Self;
  fn strings(self, list: &amp;[&amp;String]) -&gt; Self;
  // etc...
  </code></pre>
  
  <p>I would like to accept generously so I would like to accept <code>&amp;String</code>, <code>&amp;str</code>, and hopefully keys in a <code>HashMap</code> (since this might be used with a large routing table) so I thought I would accept an iterator over items that implement <code>Borrow&lt;str&gt;</code> like so:</p>
  
  <pre><code>fn strings&lt;P, Sp&gt;(self, P)
  where P: Iterator&lt;Item = &amp;'p Sp&gt;,
    Sp: Borrow&lt;str&gt; + 'p;
  </code></pre>
  
  <p>A full example is available <a href="https://play.rust-lang.org/?gist=43eb09db15f9a314538a&amp;version=stable" rel="nofollow">here</a>.</p>
  
  <p>This was great until I needed to add another optional list of strings (extensions) to the builder.</p>
  
  <p>This meant that if I created a builder without specifying both lists of strings that the compiler would complain that it couldn't infer the type of the <code>Builder</code>, which makes sense. The only reason this is not OK is that both these fields are optional so the user might never know the type of a field it hasn't yet set.</p>
  
  <p>Does anyone have any ideas on how to specify an iterator over traits? Then I wouldn't have to specify the type fully at compile time. Or maybe just a better way to do this entirely?</p>