title: Dereferencing strings and HashMaps in Rust
body: <p>I'm trying to understand how HashMaps work in Rust and I have come up with this example. </p>
  
  <pre><code>use std::collections::HashMap;
  
  fn main() {
      let mut roman2number: HashMap&lt;&amp;'static str, i32&gt; = HashMap::new();
      roman2number.insert("X", 10);
      roman2number.insert("I", 1);
  
      let roman_num = "XXI".to_string();
      let r0 = roman_num.chars().take(1).collect::&lt;String&gt;();
      let r1: &amp;str = &amp;r0.to_string();
      println!("{:?}", roman2number.get(r1)); // This works
  
      // println!("{:?}", roman2number.get(&amp;r0.to_string())); // This doesn't
  }
  </code></pre>
  
  <p>When I try to compile the code with last line uncommented, I get the following error</p>
  
  <pre><code>error: the trait bound `&amp;str: std::borrow::Borrow&lt;std::string::String&gt;` is not satisfied [E0277]
  println!("{:?}", roman2number.get(&amp;r0.to_string()));
                                              ^~~
  note: in this expansion of format_args!
  note: in this expansion of print! (defined in &lt;std macros&gt;)
  note: in this expansion of println! (defined in &lt;std macros&gt;)
  help: run `rustc --explain E0277` to see a detailed explanation
  </code></pre>
  
  <p>The Trait implementation section of the <a href="https://doc.rust-lang.org/stable/std/string/struct.String.html" rel="noreferrer">docs</a> gives the dereferencing as <code>fn deref(&amp;self) -&gt; &amp;str</code></p>
  
  <p>So what is happening here?</p>