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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use crate::directions::error::Error;
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum Status {
#[serde(alias = "INVALID_REQUEST")]
InvalidRequest,
#[serde(alias = "MAX_ROUTE_LENGTH_EXCEEDED")]
MaxRouteLengthExceeded,
#[serde(alias = "MAX_WAYPOINTS_EXCEEDED")]
MaxWaypointsExceeded,
#[serde(alias = "NOT_FOUND")]
NotFound,
#[serde(alias = "OK")]
Ok,
#[serde(alias = "OVER_DAILY_LIMIT")]
OverDailyLimit,
#[serde(alias = "OVER_QUERY_LIMIT")]
OverQueryLimit,
#[serde(alias = "REQUEST_DENIED")]
RequestDenied,
#[serde(alias = "UNKNOWN_ERROR")]
UnknownError,
#[serde(alias = "ZERO_RESULTS")]
ZeroResults,
}
impl std::convert::From<&Status> for String {
fn from(status: &Status) -> String {
match status {
Status::InvalidRequest => String::from("INVALID_REQUEST"),
Status::MaxRouteLengthExceeded => String::from("MAX_ROUTE_LENGTH_EXCEEDED"),
Status::MaxWaypointsExceeded => String::from("MAX_WAYPOINTS_EXCEEDED"),
Status::NotFound => String::from("NOT_FOUND"),
Status::Ok => String::from("OK"),
Status::OverDailyLimit => String::from("OVER_DAILY_LIMIT"),
Status::OverQueryLimit => String::from("OVER_QUERY_LIMIT"),
Status::RequestDenied => String::from("REQUEST_DENIED"),
Status::UnknownError => String::from("UNKNOWN_ERROR"),
Status::ZeroResults => String::from("ZERO_RESULTS"),
}
}
}
impl std::convert::TryFrom<String> for Status {
type Error = crate::directions::error::Error;
fn try_from(status: String) -> Result<Status, Error> {
match status.as_ref() {
"INVALID_REQUEST" => Ok(Status::InvalidRequest),
"MAX_ROUTE_LENGTH_EXCEEDED" => Ok(Status::MaxRouteLengthExceeded),
"MAX_WAYPOINTS_EXCEEDED" => Ok(Status::MaxWaypointsExceeded),
"NOT_FOUND" => Ok(Status::NotFound),
"OK" => Ok(Status::Ok),
"OVER_DAILY_LIMIT" => Ok(Status::OverDailyLimit),
"OVER_QUERY_LIMIT" => Ok(Status::OverQueryLimit),
"REQUEST_DENIED" => Ok(Status::RequestDenied),
"UNKNOWN_ERROR" => Ok(Status::UnknownError),
"ZERO_RESULTS" => Ok(Status::ZeroResults),
_ => Err(Error::InvalidStatusCode(status)),
}
}
}
impl std::default::Default for Status {
fn default() -> Self {
Status::Ok
}
}
impl std::fmt::Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Status::InvalidRequest => write!(f, "Invalid Request"),
Status::MaxRouteLengthExceeded => write!(f, "Maximum Route Length Exceeded"),
Status::MaxWaypointsExceeded => write!(f, "Maximum Waypoints Exceeded"),
Status::NotFound => write!(f, "Not Found"),
Status::Ok => write!(f, "OK"),
Status::OverDailyLimit => write!(f, "Over Daily Limit"),
Status::OverQueryLimit => write!(f, "Over Query Limit"),
Status::RequestDenied => write!(f, "Request Denied"),
Status::UnknownError => write!(f, "Unknown Error"),
Status::ZeroResults => write!(f, "Zero Results"),
}
}
}