Impl Future<Output = Result<_, reqwest::Error>> doesn't implement Debug

How can i implement the debug trait for impl Future<Output = Result<_, reqwest::Error>>


        let client = Client::new();
        let response = client.post(API_URL_INIT_TRANSACTION)
            .json(&payload)
            .headers(self.construct_headers(true))
            .send()
            .await.unwrap();

        println!("{:?}", response.json());

Add an .await

2 Likes

I get another error

type inside async fn body must be known in this context
cannot infer type for type parameter T declared on the associated function json

If you just want to print the response, use the text() method instead. The json() method requires that you specify what type you want to parse the json into.

1 Like

Awesome, Thanks it works.

But let's say i wanted parse it into a specific type how would i go about doing that, please could you give me an example?

use serde::Deserialize;

#[derive(Deserialize)]
struct MyType {
    my_field: String,
}

let body: MyType = response.json().await.unwrap();

or

let body = response.json::<MyType>().await.unwrap();
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.