From 8057f50f540443b5a012cacda4134d239e551fc6 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 5 Apr 2021 11:00:41 +0200 Subject: [PATCH] Removed unnecessary String cloning --- src/errors.rs | 5 ++--- src/ivago/controller/search.rs | 2 +- src/ivago/controller/structs/street.rs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 6403235..cf78244 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,3 @@ -use reqwest::Error; use rocket::http::Status; pub enum FejError { @@ -16,8 +15,8 @@ impl From for Status { } // TODO make this more advanced where possible -impl From for FejError { - fn from(_: Error) -> FejError { +impl From for FejError { + fn from(_: reqwest::Error) -> FejError { FejError::FailedRequest } } diff --git a/src/ivago/controller/search.rs b/src/ivago/controller/search.rs index 8f5d8ff..68c1d1f 100644 --- a/src/ivago/controller/search.rs +++ b/src/ivago/controller/search.rs @@ -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.clone()) { + match Street::try_from(value) { Ok(street) => output.push(street), Err(_) => continue, } diff --git a/src/ivago/controller/structs/street.rs b/src/ivago/controller/structs/street.rs index 257d694..e26c3a0 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 for Street { +impl TryFrom<&String> for Street { type Error = (); - fn try_from(value: String) -> Result { + fn try_from(value: &String) -> Result { if let Some(index) = value.find('(') { Ok(Street { name: (value[0..index - 1].trim()).to_string(),