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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::geocoding::error::Error;
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum LocationType {
#[serde(alias = "APPROXIMATE")]
Approximate,
#[serde(alias = "GEOMETRIC_CENTER")]
GeometricCenter,
#[serde(alias = "RANGE_INTERPOLATED")]
RangeInterpolated,
#[serde(alias = "ROOFTOP")]
RoofTop,
}
impl std::convert::From<&LocationType> for String {
fn from(location_type: &LocationType) -> String {
match location_type {
LocationType::Approximate => String::from("APPROXIMATE"),
LocationType::GeometricCenter => String::from("GEOMETRIC_CENTER"),
LocationType::RangeInterpolated => String::from("RANGE_INTERPOLATED"),
LocationType::RoofTop => String::from("ROOFTOP"),
}
}
}
impl std::convert::TryFrom<String> for LocationType {
type Error = crate::geocoding::error::Error;
fn try_from(location_type: String) -> Result<LocationType, Error> {
match location_type.as_ref() {
"APPROXIMATE" => Ok(LocationType::Approximate),
"GEOMETRIC_CENTER" => Ok(LocationType::GeometricCenter),
"RANGE_INTERPOLATED" => Ok(LocationType::RangeInterpolated),
"ROOFTOP" => Ok(LocationType::RoofTop),
_ => Err(Error::InvalidLocationTypeCode(location_type)),
}
}
}
impl std::default::Default for LocationType {
fn default() -> Self {
LocationType::Approximate
}
}
impl std::fmt::Display for LocationType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
LocationType::Approximate => write!(f, "Approximate"),
LocationType::GeometricCenter => write!(f, "Geometric Center"),
LocationType::RangeInterpolated => write!(f, "Range Interpolated"),
LocationType::RoofTop => write!(f, "Roof Top"),
}
}
}