optimized main

master
Mathias Rothenhaeusler 2021-09-17 19:16:32 +02:00
parent 4f80acb5e9
commit a7b609b93e
1 changed files with 7 additions and 1 deletions

View File

@ -1,3 +1,5 @@
use std::str::FromStr;
use deepl::deepl_helper::Params; use deepl::deepl_helper::Params;
use hyper::{Body, Client, Method, Request, body}; use hyper::{Body, Client, Method, Request, body};
use hyper_tls::HttpsConnector; use hyper_tls::HttpsConnector;
@ -20,6 +22,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let body_bytes = body::to_bytes(res.into_body()).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"); let body = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8");
let v: Value = serde_json::from_str(&body)?; let v: Value = serde_json::from_str(&body)?;
println!("{}", v["translations"][0]["text"]); let result = String::from_str(match v["translations"][0]["text"].as_str() {
Some(text) => text,
None => "No results"
}).unwrap();
println!("{}", result.replace("\"", ""));
Ok(()) Ok(())
} }