2020-11-13 11:45:37 +01:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2020-11-11 16:17:37 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
2020-11-11 15:48:24 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
2020-11-11 16:17:37 +01:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2020-11-11 15:48:24 +01:00
|
|
|
pub enum FacetType {
|
|
|
|
String,
|
2020-11-13 11:45:37 +01:00
|
|
|
Float,
|
|
|
|
Integer,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for FacetType {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
FacetType::String => f.write_str("string"),
|
|
|
|
FacetType::Float => f.write_str("float"),
|
|
|
|
FacetType::Integer => f.write_str("integer"),
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 15:48:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:45:37 +01:00
|
|
|
impl FromStr for FacetType {
|
|
|
|
type Err = InvalidFacetType;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
if s.eq_ignore_ascii_case("string") {
|
|
|
|
Ok(FacetType::String)
|
|
|
|
} else if s.eq_ignore_ascii_case("float") {
|
|
|
|
Ok(FacetType::Float)
|
|
|
|
} else if s.eq_ignore_ascii_case("integer") {
|
|
|
|
Ok(FacetType::Integer)
|
|
|
|
} else {
|
|
|
|
Err(InvalidFacetType)
|
|
|
|
}
|
2020-11-11 15:48:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-13 11:45:37 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
|
|
|
|
pub struct InvalidFacetType;
|
|
|
|
|
|
|
|
impl fmt::Display for InvalidFacetType {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.write_str(r#"Invalid facet type, must be "string", "float" or "integer""#)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for InvalidFacetType { }
|