From e7bd93c3a4d25ddff1874a57df37f23ae9d90ec4 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 5 Apr 2021 11:10:48 +0200 Subject: [PATCH] Switched another function call to &str --- src/ivago/controller/search.rs | 4 ++-- src/ivago/controller/structs/street.rs | 4 ++-- src/ivago/mod.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ivago/controller/search.rs b/src/ivago/controller/search.rs index 68c1d1f..8c84113 100644 --- a/src/ivago/controller/search.rs +++ b/src/ivago/controller/search.rs @@ -14,7 +14,7 @@ const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garba /// * `street` - name of the street /// * `city` - city the street is in // TODO find out how to do this async -pub fn search_streets(street_name: &String) -> Result, FejError> { +pub fn search_streets(street_name: &str) -> Result, FejError> { let client = reqwest::Client::new(); let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?; let data: Vec> = response.json()?; @@ -24,7 +24,7 @@ pub fn search_streets(street_name: &String) -> Result, FejError> { // We iterate over every item and extract the needed data for map in data.iter() { if let Some(value) = map.get("value") { - match Street::try_from(value) { + match Street::try_from(value.as_str()) { Ok(street) => output.push(street), Err(_) => continue, } diff --git a/src/ivago/controller/structs/street.rs b/src/ivago/controller/structs/street.rs index e26c3a0..35f7e16 100644 --- a/src/ivago/controller/structs/street.rs +++ b/src/ivago/controller/structs/street.rs @@ -28,10 +28,10 @@ impl Serialize for Street { } } -impl TryFrom<&String> for Street { +impl TryFrom<&str> for Street { type Error = (); - fn try_from(value: &String) -> Result { + fn try_from(value: &str) -> Result { if let Some(index) = value.find('(') { Ok(Street { name: (value[0..index - 1].trim()).to_string(), diff --git a/src/ivago/mod.rs b/src/ivago/mod.rs index cc916d0..78b1fc2 100644 --- a/src/ivago/mod.rs +++ b/src/ivago/mod.rs @@ -13,7 +13,7 @@ pub fn routes() -> Vec { #[get("/search?")] pub fn route_search_streets(street: String) -> Result>, Status> { - Ok(Json(search_streets(&street)?)) + Ok(Json(search_streets(street.as_str())?)) } #[get("/?&&&")]