Removed unnecessary String cloning

master
Jef Roosens 2021-04-05 11:00:41 +02:00
parent ea72231612
commit 8057f50f54
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
3 changed files with 5 additions and 6 deletions

View File

@ -1,4 +1,3 @@
use reqwest::Error;
use rocket::http::Status; use rocket::http::Status;
pub enum FejError { pub enum FejError {
@ -16,8 +15,8 @@ impl From<FejError> for Status {
} }
// TODO make this more advanced where possible // TODO make this more advanced where possible
impl From<Error> for FejError { impl From<reqwest::Error> for FejError {
fn from(_: Error) -> FejError { fn from(_: reqwest::Error) -> FejError {
FejError::FailedRequest FejError::FailedRequest
} }
} }

View File

@ -24,7 +24,7 @@ pub fn search_streets(street_name: &String) -> Result<Vec<Street>, FejError> {
// We iterate over every item and extract the needed data // We iterate over every item and extract the needed data
for map in data.iter() { for map in data.iter() {
if let Some(value) = map.get("value") { if let Some(value) = map.get("value") {
match Street::try_from(value.clone()) { match Street::try_from(value) {
Ok(street) => output.push(street), Ok(street) => output.push(street),
Err(_) => continue, Err(_) => continue,
} }

View File

@ -28,10 +28,10 @@ impl Serialize for Street {
} }
} }
impl TryFrom<String> for Street { impl TryFrom<&String> for Street {
type Error = (); type Error = ();
fn try_from(value: String) -> Result<Self, Self::Error> { fn try_from(value: &String) -> Result<Self, Self::Error> {
if let Some(index) = value.find('(') { if let Some(index) = value.find('(') {
Ok(Street { Ok(Street {
name: (value[0..index - 1].trim()).to_string(), name: (value[0..index - 1].trim()).to_string(),