use reqwest::Url; use serde_derive::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Element { pub id: Box, pub name: Box, pub simple_name: Box, pub color: u64 } impl Element{ async fn get(element: &str) -> Element { let url = format!("http://localhost:3000/api/elements/{}", element); let url = Url::parse(&*url).expect("Can't convert url"); return reqwest::get(url).await.expect("Can't access Url").json::().await.expect("Wrong json format"); } async fn get_all() -> Vec> { let url = format!("http://localhost:3000/api/elements"); let url = Url::parse(&*url).expect("Can't convert url"); return reqwest::get(url).await.expect("Can't access Url").json::>>().await.expect("Wrong json format"); } } pub async fn test_elem() { println!("All elems : {:?}", Element::get_all().await); let geo = Element::get("geo").await; println!("Name : {}\nColor : #{:x}", geo.name, geo.color); }