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
use rust_decimal::Decimal;
#[derive(Debug)]
pub enum Error {
InvalidLanguageCode(String),
InvalidLatitude(Decimal, Decimal),
InvalidLongitude(Decimal, Decimal),
InvalidPlaceTypeCode(String),
InvalidRegionCode(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::InvalidLanguageCode(language_code) => write!(f,
"Google Maps Platform API client: \
`{}` is not a recognized language code.
For a list of supported languages see \
https://developers.google.com/maps/faq#languagesupport",
language_code),
Error::InvalidLatitude(latitude, longitude) => write!(f,
"Google Maps Platform API client: \
`{lat}` from the `{lat},{lng}` pair is an invalid latitudinal value.
A latitude must be between -90.0° and 90.0°.",
lat=latitude, lng=longitude),
Error::InvalidLongitude(latitude, longitude) => write!(f,
"Google Maps Platform API client: \
`{lng}` from the `{lat},{lng}` pair is an invalid longitudinal value.
A longitude must be between -180.0° and 180.0°.",
lat=latitude, lng=longitude),
Error::InvalidPlaceTypeCode(place_type_code) => write!(f,
"Google Maps Platform API client: \
`{}` is not a recognized place type code.
For a list of supported place types see \
https://developers.google.com/places/web-service/supported_types",
place_type_code),
Error::InvalidRegionCode(region_code) => write!(f,
"Google Maps Platform API client: \
`{}` is not a recognized region code.
For a list of supported regions see \
https://developers.google.com/maps/coverage",
region_code),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::InvalidLanguageCode(_language_code) => None,
Error::InvalidLatitude(_latitude, _longitude) => None,
Error::InvalidLongitude(_latitude, _longitude) => None,
Error::InvalidPlaceTypeCode(_place_type_code) => None,
Error::InvalidRegionCode(_region_code) => None,
}
}
}