optimized main
This commit is contained in:
+7
-1
@@ -1,3 +1,5 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use deepl::deepl_helper::Params;
|
||||
use hyper::{Body, Client, Method, Request, body};
|
||||
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 = String::from_utf8(body_bytes.to_vec()).expect("response was not valid utf-8");
|
||||
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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user