From 27a61f8a9a1571793f50880ffbad01a4a9da1551 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 3 Apr 2021 22:40:22 +0200 Subject: [PATCH] [#4] Started implementing needed traits (#4) --- src/ivago/controller/pickup_times.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ivago/controller/pickup_times.rs b/src/ivago/controller/pickup_times.rs index aa86a1d..1f037a2 100644 --- a/src/ivago/controller/pickup_times.rs +++ b/src/ivago/controller/pickup_times.rs @@ -1,5 +1,7 @@ use super::search::Street; use chrono::NaiveDate; +use rocket::http::RawStr; +use rocket::request::FromFormValue; use std::error::Error; const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling"; @@ -13,6 +15,17 @@ pub struct PickupTime { url: String, } +impl<'v> FromFormValue<'v> for NaiveDate { + type Error = &'v RawStr; + + fn from_form_value(form_value: &'v RawStr) -> Result { + match NaiveDate::parse_from_str(form_value, "%Y-%m-%d") { + Ok(date) => Ok(date), + Err(_) => Err(form_value), + } + } +} + pub fn get_pickup_times( street: Street, number: u64,