title: Can a function accept an argument of type Option or &str or String?
body: <p>I'm trying to create a fast, flexible and convenient API that accepts an optional string parameter. I wish the user to be able to pass:</p>
  
  <ul>
  <li><code>None</code></li>
  <li><code>"foo"</code></li>
  <li><code>"foo".to_string()</code></li>
  <li><code>Some("foo")</code> (equivalent to <code>"foo"</code>)</li>
  <li><code>Some("foo".to_string())</code> (equivalent to <code>"foo".to_string()</code>)</li>
  </ul>
  
  <p>As far as I know, the best solution to handle <code>"foo"</code> or <code>"foo".to_string()</code> is <code>Into&lt;Cow&lt;'a, str&gt;&gt;</code>. On the other hand, the best solution to handle <code>"foo"</code> or <code>Some("foo")</code> is <code>Into&lt;Option&lt;&amp;'a str&gt;&gt;</code>.</p>
  
  <p>Thus I tried with this but it doesn't compile:</p>
  
  <pre><code>fn foo&lt;'a, T, O&gt;(_bar: O)
  where
      T: Into&lt;Cow&lt;'a, str&gt;&gt;,
      O: Into&lt;Option&lt;T&gt;&gt;,
  </code></pre>
  
  
  
  <pre><code>foo(Some("aaa"));
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0283]: type annotations required: cannot resolve `_: std::convert::Into&lt;std::borrow::Cow&lt;'_, str&gt;&gt;`
    --&gt; src/main.rs:12:5
     |
  12 |     foo(Some("aaa"));
     |     ^^^
     |
  note: required by `foo`
    --&gt; src/main.rs:3:1
     |
  3  | / fn foo&lt;'a, T, O&gt;(_bar: O)
  4  | | where
  5  | |     T: Into&lt;Cow&lt;'a, str&gt;&gt;,
  6  | |     O: Into&lt;Option&lt;T&gt;&gt;,
  7  | | {}
     | |__^
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=06b2d72871ac81b705f2b8f2ca94ffe7&amp;version=stable" rel="nofollow noreferrer">Playground</a></p>
  
  <p>Is it possible to make it work?</p>