title: How to fix: cannot infer an appropriate lifetime for automatic coercion
body: <p>I managed to run into a lifetime issue again that I seem to be unable to resolve on my own.</p>
  
  <p>The compiler tells me <em>cannot infer an appropriate lifetime for automatic coercion</em></p>
  
  <p><img src="https://i.stack.imgur.com/DSaVN.png" alt="enter image description here"></p>
  
  <p>I tried to follow the compilers suggestion and introduced the lifetime annotations in the <code>handle_request</code> method.</p>
  
  <pre><code>fn handle_request&lt;'a&gt;(&amp;self, req: &amp;Request, res: &amp;'a mut ResponseWriter) {
  
  
      fn set_headers(req: &amp;Request, res: &amp;mut ResponseWriter) {
          //probably not important for the example 
      }
  
      match &amp;req.request_uri {
          &amp;AbsolutePath(ref url) =&gt; {
              match self.router.match_route(req.method.clone(), url.clone()) {
                  Some(route_result) =&gt; { 
                      set_headers(req, res); 
  
                      let floor_req = request::Request{
                          origin: req,
                          params: route_result.params.clone()
                      };
  
                      let floor_res = response::Response{
                          origin: res
                      };
  
                      (route_result.route.handler)(floor_req, &amp;mut floor_res);
                  },
                  None =&gt; {}
              }
          },
          _ =&gt; set_headers(req, res)
      }
  }
  </code></pre>
  
  <p>I had the code working before but now I wanted to wrap the <code>http::server::ResponseWriter</code> in my own <code>Response</code> struct. I did exactly the same for the <code>Request</code> before but in terms of lifetimes the case seems to be slightly different. Maybe because it's a <code>&amp;mut</code> instead of just a simple <code>&amp;</code> reference.</p>
  
  <p>This is my <strong><code>ResponseWriter</code></strong> struct.</p>
  
  <pre><code>use http;
  
  ///A container for the response
  pub struct Response&lt;'a&gt; {
      ///the original `http::server::ResponseWriter`
      pub origin: &amp;'a mut http::server::ResponseWriter&lt;'a&gt;,
  }
  </code></pre>
  
  <p>Just incase any Samaritan wants to compile the code locally, I pushed it into the <em>lifetime_crazyness</em> branch here: <a href="https://github.com/cburgdorf/Floor/commits/lifetime_craziness" rel="noreferrer">https://github.com/cburgdorf/Floor/commits/lifetime_craziness</a></p>
  
  <p>Just run <code>make floor</code> to compile it.</p>