title: Static lifetime requirements for managed state
body: <p>I'm having troubles with a managed <code>State</code> with <code>Rocket</code>. This state holds a Database connection and a collection of Cursors on that Database. Each one of theses have a reference on the  Database.</p>
  
  <p>One of the operations on that state require to create a new cursor on the Database and keep it for later use. Unfortunatly, I am stuck with a lifetime problem. Usually, I have no problem dealing with thoses, but right now, I'm out of ideas...</p>
  
  <p>I have recreated the problem bellow in a short example. </p>
  
  <pre class="lang-rust prettyprint-override"><code>#![feature(proc_macro_hygiene, decl_macro)]
  #[macro_use]
  extern crate rocket;
  
  use rocket::State;
  
  struct Database;
  
  impl Database {
      fn create_cursor(&amp;self) -&gt; Cursor {
          Cursor { database: self }
      }
  }
  
  struct Cursor&lt;'a&gt; {
      database: &amp;'a Database
  }
  
  struct Controller&lt;'a&gt; {
      database: Database,
      cursors: Vec&lt;Cursor&lt;'a&gt;&gt;,
  }
  
  impl&lt;'a&gt; Controller&lt;'a&gt; {
      fn do_work(&amp;'a mut self) {
          let cursor = self.database.create_cursor();
          self.cursors.push(cursor)
      }
  }
  
  fn main() {
      let database = Database;
      let controller = Controller { database, cursors: Vec::new() };
  
      rocket::ignite()
          .manage(controller)
          .launch();
  }
  
  #[get("/")]
  pub fn do_work_route(
      mut controller: State&lt;'static, Controller&lt;'static&gt;&gt;
  ) -&gt; &amp;'static str {
      controller.do_work();
      "Something..."
  }
  </code></pre>
  
  <pre><code>error[E0621]: explicit lifetime required in the type of `__req`
    --&gt; src/main.rs:42:9
     |
  40 | #[get("/")]
     | ----------- help: add explicit lifetime `'static` to the type of `__req`: `&amp;'_b rocket::Request&lt;'static&gt;`
  41 | pub fn do_work_route(
  42 |     mut controller: State&lt;'static, Controller&lt;'static&gt;&gt;
     |         ^^^^^^^^^^ lifetime `'static` required
  </code></pre>
  
  <p>Any lead would be appreciated. Meanwhile, I'll continue digging. </p>
  
  <p>Thanks a lot!</p>