Switched another function call to &str

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

View File

@ -14,7 +14,7 @@ const SEARCH_URL: &str = "https://www.ivago.be/nl/particulier/autocomplete/garba
/// * `street` - name of the street /// * `street` - name of the street
/// * `city` - city the street is in /// * `city` - city the street is in
// TODO find out how to do this async // TODO find out how to do this async
pub fn search_streets(street_name: &String) -> Result<Vec<Street>, FejError> { pub fn search_streets(street_name: &str) -> Result<Vec<Street>, FejError> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?; let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?;
let data: Vec<HashMap<String, String>> = response.json()?; let data: Vec<HashMap<String, String>> = response.json()?;
@ -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) { match Street::try_from(value.as_str()) {
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<&str> for Street {
type Error = (); type Error = ();
fn try_from(value: &String) -> Result<Self, Self::Error> { fn try_from(value: &str) -> 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(),

View File

@ -13,7 +13,7 @@ pub fn routes() -> Vec<rocket::Route> {
#[get("/search?<street>")] #[get("/search?<street>")]
pub fn route_search_streets(street: String) -> Result<Json<Vec<Street>>, Status> { pub fn route_search_streets(street: String) -> Result<Json<Vec<Street>>, Status> {
Ok(Json(search_streets(&street)?)) Ok(Json(search_streets(street.as_str())?))
} }
#[get("/?<street>&<number>&<start_date>&<end_date>")] #[get("/?<street>&<number>&<start_date>&<end_date>")]