title: How do I share a HashMap between Hyper handlers?
body: <p>I'm attempting to learn Rust by implementing a simple in-memory URL shortener with Hyper 0.10. I'm running into an issue that I think is caused by trying to close over a mutable <code>HashMap</code> in my handler:</p>
  
  <pre><code>fn post(mut req: Request, mut res: Response, short_uris: &amp;mut HashMap&lt;&amp;str, &amp;str&gt;) {
      let mut body = String::new();
      match req.read_to_string(&amp;mut body) {
          Ok(_) =&gt; {
              let key = short_uris.len();
              short_uris.insert(&amp;key.to_string(), &amp;body.to_string());
              *res.status_mut() = StatusCode::Created;
              res.start().unwrap().write(&amp;key.to_string().into_bytes());
          },
          Err(_) =&gt; *res.status_mut() = StatusCode::BadRequest
      }
  }
  
  fn get(req: Request, mut res: Response, short_uris: &amp;HashMap&lt;&amp;str, &amp;str&gt;) {
      match req.uri.clone() {
          AbsolutePath(path) =&gt; {
              match short_uris.get::&lt;str&gt;(&amp;path) {
                  Some(short_uri) =&gt; {
                      *res.status_mut() = StatusCode::MovedPermanently;
                      res.headers_mut().set(Location(short_uri.to_string()));
                  },
                  None =&gt; *res.status_mut() = StatusCode::NotFound
              }
          },
          _ =&gt; *res.status_mut() = StatusCode::BadRequest
      }
  }
  
  fn main() {
      let mut short_uris: HashMap&lt;&amp;str, &amp;str&gt; = HashMap::new();
      short_uris.insert("/example", "http://www.example.com");
      Server::http("0.0.0.0:3001").unwrap().handle(move |req: Request, mut res: Response| {
          match req.method {
              hyper::Post =&gt; post(req, res, &amp;mut short_uris),
              hyper::Get =&gt; get(req, res, &amp;short_uris),
              _ =&gt; *res.status_mut() = StatusCode::MethodNotAllowed
          }
      }).unwrap();
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>src/main.rs:42:40: 42:46 error: the trait bound `for&lt;'r, 'r, 'r&gt; [closure@src/main.rs:42:47: 48:3 short_uris:std::collections::HashMap&lt;&amp;str, &amp;str&gt;]: std::ops::Fn&lt;(hyper::server::Request&lt;'r, 'r&gt;, hyper::server::Response&lt;'r&gt;)&gt;` is not satisfied [E0277]
  src/main.rs:42  Server::http("0.0.0.0:3001").unwrap().handle(move |req: Request, mut res: Response| {
  </code></pre>
  
  <p>Do I need to use an <code>Arc</code> to share the <code>HashMap</code> between threads? If so, what would that look like? Also, I could be totally wrong about the issue. The error message is very cryptic to me.</p>