How to use Future

Future is update from 0.1.0 to 0.3.0
how can i use it ?

i want to use and_then and from_err fucntions.

In futures 0.3, these functions are on the futures::future::TryFutureExt trait. Import it like so to use them on the new futures:

use futures::future::TryFutureExt;

If you want all the utility functions, I would recommend importing them all at once, like so:

use futures::prelude::*;

This brings in TryFuturesExt, as well as FuturesExt and StreamExt and a few other useful utility traits.

If you're updating from futures 0.1 to futures 0.3, this blog post might be useful:

Note that with async/await, there are other ways to write those functions:

// before
fut_a.and_then(|res| make_future(res))

// after
async move {
    let res = fut_a.await;
// before

// after
async move { Err(err) }
    pub async fn get_mining_info(&self) -> Result<MiningInfoResponse, FetchError> {

        let res = self.inner



            .query(&GetMiningInfoRequest {

                request_type: &"getMiningInfo",




            .map_err(|e| FetchError::from(e))?



            .map_err(|e| FetchError::from(e));




pub enum FetchError {




i am confused with the return result.
there are two errors which one is failed to send http with reqwest::Error
and i another get wrong http back.
but in async i don't know how to parse the second error.

You would handle errors in the same way as in sync code.

i don't know how to realize it, can you help me ?

If you want help, please edit your posts to not have empty lines all over the place.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.