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
use serde_json::{self, Value as JsonValue};
use rocket::request::FromFormValue;
use rocket::http::RawStr;
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum SolutionOrdering {
BestToWorst,
WorstToBest,
}
impl SolutionOrdering {
#[allow(non_upper_case_globals)]
pub const Default: SolutionOrdering = SolutionOrdering::BestToWorst;
}
impl<'v> FromFormValue<'v> for SolutionOrdering {
type Error = ();
fn from_form_value(form_value: &'v RawStr) -> Result<Self, Self::Error> {
serde_json::from_value(JsonValue::String(form_value.to_string())).map_err(|_| ())
}
}