You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to learn how to impl Debug for actix_web or awc so that I can print the JSON response from a third party api. For example
[dependencies]
actix-web = "4"
awc = { version = "3.1.1", features = ["openssl"]}
pubasyncfnget_data(){let client = awc::Client::default();// construct requestlet req = client.get("https://jsonplaceholder.typicode.com/posts/1/comments").insert_header(("User-Agent","awc/3.0"));// send request and await responselet res = req.send().await;println!("Response: {:?}", res.unwrap().body());}
I get the following error:
error[E0277]: `ResponseBody<Decompress<actix_web::dev::Payload<Pin<Box<dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes,PayloadError>>>>>>>` doesn't implement `Debug`
--> src/get_req.rs:32:32
|
32 | println!("Response: {:?}", res.unwrap().body());
| ^^^^^^^^^^^^^^^^^^^ `ResponseBody<Decompress<actix_web::dev::Payload<Pin<Box<dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes,PayloadError>>>>>>>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `ResponseBody<Decompress<actix_web::dev::Payload<Pin<Box<dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes,PayloadError>>>>>>>`
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)For more information about this error, try `rustc --explain E0277`.
So i try to impl debug
use actix_web::dev::Decompress;use actix_web::error::PayloadError;use std::pin::Pin;use std::fmt::Debug;use std::fmt;implDebugfor awc::JsonBody<Decompress<actix_web::dev::Payload<Pin<Box<dyn futures_core::stream::Stream<Item = Result<actix_web::web::Bytes,PayloadError>>>>>>,_>{// ... dont understand what to do herefnfmt(&self,f:&mut fmt::Formatter) -> fmt::Result{write!(f,"Hi: {}",self.id)}}
I don't know where I'm suppose to import futures_core from (or the appropriate way to figure that out) or what should go inside the custom implementation of debug to print the JSON response.
N/ANot applicable or remedied without code change.
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to learn how to impl Debug for actix_web or awc so that I can print the JSON response from a third party api. For example
I get the following error:
So i try to impl debug
I don't know where I'm suppose to import futures_core from (or the appropriate way to figure that out) or what should go inside the custom implementation of debug to print the JSON response.
How do you implement Debug on actix_web or awc?
Beta Was this translation helpful? Give feedback.
All reactions