use http::Response;
use http_body_reader::ResponseExt as _;
use http_body_util::Full;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
struct SomeInfo {
id: u32,
name: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let info = SomeInfo {
id: 1234,
name: "Alice".to_string(),
};
let data = serde_json::to_vec(&info)?;
let response = Response::builder().body(Full::new(data.as_ref()))?;
assert_eq!(response.body_reader().json::<SomeInfo>().await?, info);
Ok(())
}