optimized main
parent
4f80acb5e9
commit
a7b609b93e
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue