title: How can I make a postgres pool connection global in rocket.rs and make FromRequest custom guards asyncable?
body: <p>I am making an authorization system which will implement the <code>FromRequest</code> trait from the web framework rocket, which is needed to make custom guards.</p>
  <p>The first problem I have gone into is how I have to make the connection global. Should I cast it as a constant, so it can be accessed from the functions in the implementation, or is there a cache in rocket or some form of storage where the <code>PgPool</code> connection (since I am using sqlx) can be accessed &amp; queries can be made.</p>
  <p>The second problem I have gone through is making the FromRequest functions asynchronous. Since sqlx is natively async afaik, I do not know if rocket has yet to support this. I was thinking of either making a tokio thread, or if there is a version of <code>.then()</code> in Rust, but I do not know</p>
  <pre class="lang-rs prettyprint-override"><code>#[derive(Debug)]
  struct User {
      username: String,
      password: String,
      user_id: i16,
      phone_number: String,
      display_name: String,
      //other fields omitted
  }
  
  impl&lt;'a, 'r&gt; FromRequest&lt;'a, 'r&gt; for &amp;'a User {
      type Error = !;
  
      fn from_request(request: &amp;'a Request&lt;'r&gt;) -&gt; request::Outcome&lt;&amp;'a User, !&gt; {
          let user_result = request.local_cache(|| {
              //..need to fetch user with sqlx [but sqlx is async]
              //and later get cookies and check
          }); 
  
          user_result.as_ref().or_forward(())
      }
  }
  </code></pre>