From 0125dfe26c07846df1e1fb8049298b0508e9b560 Mon Sep 17 00:00:00 2001 From: mace Date: Thu, 16 Sep 2021 17:04:54 +0200 Subject: [PATCH] first release candidate --- src/main.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4e8127d..f3826ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,7 @@ -use hyper::{Body, Client, Method, Request, Response, body}; +use hyper::{Body, Client, Method, Request, body}; use hyper_tls::HttpsConnector; -use serde::ser; +use serde_json::Value; -fn serialize(req: Response) -> serde_json::Result>> -where - T: ser::Serialize, -{ - let (parts, body) = req.into_parts(); - let body = serde_json::to_vec(&body)?; - Ok(Response::from_parts(parts, body)) -} #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { let https = HttpsConnector::new(); @@ -24,6 +16,7 @@ async fn main() -> Result<(), Box> { let res = client.request(request).await?; let body_bytes = body::to_bytes(res.into_body()).await?; let body = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8"); - println!("Body: {}", body); + let v: Value = serde_json::from_str(&body)?; + println!("{}", v["translations"][0]["text"]); Ok(()) }