title: How does AsRef work with str?
body: <p>I want to write a trait which could take a string slice directly:</p>
  
  <pre><code>use std::path::Path;
  
  trait Trait1 {}
  
  impl Trait1 for str {}
  // impl&lt;'a&gt; Trait1 for &amp;'a str {}
  
  fn run&lt;T: Trait1&gt;(_: T) {}
  fn run1&lt;T: AsRef&lt;Path&gt;&gt;(_: T) {}
  
  fn main() {
      // E0277: the trait bound `&amp;str: Trait1` is not satisfied
      // run::&lt;&amp;str&gt;("sf");
      run1::&lt;&amp;str&gt;("sf");
  }
  </code></pre>
  
  <p>Note that </p>
  
  <pre><code>run::&lt;&amp;str&gt;("sf");
  </code></pre>
  
  <p>won't compile unless <code>Trait1</code> is also implemented for <code>&amp;str</code>. However, <code>AsRef</code> works despite also <a href="https://doc.rust-lang.org/src/std/path.rs.html#2161-2165" rel="nofollow noreferrer">being implemented</a> for <code>str</code> only. Is there anything special about AsRef?</p>