title: How can future.then() return a Future?
body: <p>The function below, taken from <a href="https://github.com/hyperium/hyper/blob/42587059e6175735b1a8656c5ddbff0edb19294c/src/client/client.rs#L326" rel="nofollow noreferrer">here</a>:</p>
  <pre><code>fn connection_for(
      &amp;self,
      pool_key: PoolKey,
  ) -&gt; impl Future&lt;Output = Result&lt;Pooled&lt;PoolClient&lt;B&gt;&gt;, ClientError&lt;B&gt;&gt;&gt; {
  
      let checkout = self.pool.checkout(pool_key.clone());
      let connect = self.connect_to(pool_key);
  
      let executor = self.conn_builder.exec.clone();
      // The order of the `select` is depended on below...
      future::select(checkout, connect).then(move |either| match either {
           ...
  </code></pre>
  <p>should return a <code>Future</code>. However, it returns the return result of</p>
  <pre><code>    future::select(checkout, connect).then(...)
  </code></pre>
  <p>Where <code>.then</code> does this:</p>
  <pre><code>fn then&lt;Fut, F&gt;(self, f: F) -&gt; Then&lt;Self, Fut, F&gt;
  </code></pre>
  <p>Which is not a <code>Future</code>. How it this possible?</p>
  <p>I'm trying to understand what is returned by this function. This is the end of the '.then':</p>
  <pre><code>       Either::Right((Err(err), checkout)) =&gt; Either::Right(Either::Right({
              if err.is_canceled() {
                  Either::Left(checkout.map_err(ClientError::Normal))
              } else {
                  Either::Right(future::err(ClientError::Normal(err)))
              }
          })),
  </code></pre>
  <p>It looks like it returns <code>Either::Right(Either::Right</code> of something. I'm confused.</p>