1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use rocket::request::{FromForm, FormItems};
use rocket::request::FromFormValue;
use rocket::http::RawStr;
#[derive(Serialize, Deserialize, Clone, PartialEq)]
pub enum TripSort {
ArrivalTime,
DepartureTime,
DirectionId,
ServiceId,
RouteId,
Uid,
None
}
impl<'f> FromFormValue<'f> for TripSort {
type Error = ();
fn from_form_value(form_value: &RawStr) -> Result<Self, <Self as FromFormValue>::Error> {
Ok(match form_value.to_lowercase().as_str() {
"arrivaltime" => TripSort::ArrivalTime,
"departuretime" => TripSort::DepartureTime,
"directionid" => TripSort::DirectionId,
"serviceid" => TripSort::ServiceId,
"routeid" => TripSort::RouteId,
"uid" => TripSort::Uid,
_ => TripSort::None
})
}
}