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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//! Attributes describing a place. Not all attributes will be available for all
//! place types.
use crate::places::{
BusinessStatus, PlaceEditorialSummary, PlaceOpeningHours, PlacePhoto, PlaceReview,
};
use crate::types::{AddressComponent, Geometry, PlaceType};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
// -----------------------------------------------------------------------------
//
/// Attributes describing a place. Not all attributes will be available for all
/// place types.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
pub struct Place {
/// An array containing the separate components applicable to this address.
///
/// See [AddressComponent](https://developers.google.com/maps/documentation/places/web-service/search-text#AddressComponent)
/// for more information.
#[serde(default)]
pub address_components: Vec<AddressComponent>,
/// A representation of the place's address in the
/// [adr microformat](http://microformats.org/wiki/adr).
#[serde(default)]
pub adr_address: Option<String>,
/// Indicates the operational status of the place, if it is a business. If
/// no data exists, `business_status` is not returned.
///
/// The allowed values include: `OPERATIONAL`, `CLOSED_TEMPORARILY`, and
/// `CLOSED_PERMANENTLY`
#[serde(default)]
pub business_status: Option<BusinessStatus>,
/// Specifies if the business supports curbside pickup.
#[serde(default)]
pub curbside_pickup: Option<bool>,
/// Contains the hours of operation for the next seven days (including
/// today). The time period starts at midnight on the date of the request
/// and ends at 11:59 pm six days later. This field includes the
/// `special_days` subfield of all hours, set for dates that have
/// exceptional hours.
///
/// See [PlaceOpeningHours](https://developers.google.com/maps/documentation/places/web-service/search-text#PlaceOpeningHours)
/// for more information.
#[serde(default)]
pub current_opening_hours: Option<PlaceOpeningHours>,
/// Specifies if the business supports delivery.
#[serde(default)]
pub delivery: Option<bool>,
/// Specifies if the business supports indoor or outdoor seating options.
#[serde(default)]
pub dine_in: Option<bool>,
/// Contains a summary of the place. A summary is comprised of a textual
/// overview, and also includes the language code for these if applicable.
/// Summary text must be presented as-is and can not be modified or altered.
///
/// See [PlaceEditorialSummary](https://developers.google.com/maps/documentation/places/web-service/search-text#PlaceEditorialSummary)
/// for more information.
#[serde(default)]
pub editorial_summary: Option<PlaceEditorialSummary>,
/// A string containing the human-readable address of this place.
///
/// Often this address is equivalent to the postal address. Note that some
/// countries, such as the United Kingdom, do not allow distribution of true
/// postal addresses due to licensing restrictions.
///
/// The formatted address is logically composed of one or more address
/// components. For example, the address "111 8th Avenue, New York, NY"
/// consists of the following components: "111" (the street number), "8th
/// Avenue" (the route), "New York" (the city) and "NY" (the US state).
///
/// Do not parse the formatted address programmatically. Instead you should
/// use the individual address components, which the API response includes
/// in addition to the formatted address field.
#[serde(default)]
pub formatted_address: Option<String>,
/// Contains the place's phone number in its
/// [local format](http://en.wikipedia.org/wiki/Local_conventions_for_writing_telephone_numbers).
#[serde(default)]
pub formatted_phone_number: Option<String>,
/// Contains the location and viewport for the location.
///
/// See [Geometry](https://developers.google.com/maps/documentation/places/web-service/search-text#Geometry) for more information.
#[serde(default)]
pub geometry: Option<Geometry>,
/// Contains the URL of a suggested icon which may be displayed to the user
/// when indicating this result on a map.
#[serde(default)]
pub icon: Option<String>,
/// Contains the default HEX color code for the place's category.
#[serde(default)]
pub icon_background_color: Option<String>,
/// Contains the URL of a recommended icon, minus the `.svg` or `.png` file
/// type extension.
#[serde(default)]
pub icon_mask_base_uri: Option<String>,
/// Contains the place's phone number in international format. International
/// format includes the country code, and is prefixed with the plus, +,
/// sign. For example, the `international_phone_number` for Google's Sydney,
/// Australia office is `+61 2 9374 4000`.
#[serde(default)]
pub international_phone_number: Option<String>,
/// Contains the human-readable name for the returned result. For
/// `establishment` results, this is usually the canonicalized business
/// name.
#[serde(default)]
pub name: Option<String>,
/// Contains the regular hours of operation.
///
/// See [PlaceOpeningHours](https://developers.google.com/maps/documentation/places/web-service/search-text#PlaceOpeningHours)
/// for more information.
#[serde(default)]
pub opening_hours: Option<PlaceOpeningHours>,
/// An array of photo objects, each containing a reference to an image. A
/// request may return up to ten photos. More information about place photos
/// and how you can use the images in your application can be found in the
/// [Place Photos](https://developers.google.com/maps/documentation/places/web-service/photos)
/// documentation.
///
/// See [PlacePhoto](https://developers.google.com/maps/documentation/places/web-service/search-text#PlacePhoto)
/// for more information.
#[serde(default)]
pub photos: Vec<PlacePhoto>,
/// A textual identifier that uniquely identifies a place. To retrieve
/// information about the place, pass this identifier in the `place_id`
/// field of a Places API request. For more information about place IDs, see
/// the [place ID overview](https://developers.google.com/maps/documentation/places/web-service/place-id).
#[serde(default)]
pub place_id: Option<String>,
/// The price level of the place, on a scale of 0 to 4. The exact amount
/// indicated by a specific value will vary from region to region. Price
/// levels are interpreted as follows:
///
/// * 0 Free
/// * 1 Inexpensive
/// * 2 Moderate
/// * 3 Expensive
/// * 4 Very Expensive
#[serde(default)]
pub price_level: Option<u8>,
/// Contains the place's rating, from 1.0 to 5.0, based on aggregated user
/// reviews.
#[serde(default)]
pub rating: Option<Decimal>,
/// Specifies if the place supports reservations.
#[serde(default)]
pub reservable: Option<bool>,
/// A JSON array of up to five reviews. By default, the reviews are sorted
/// in order of relevance. Use the `reviews_sort` request parameter to
/// control sorting.
///
/// * For `most_relevant` (default), reviews are sorted by relevance; the
/// service will bias the results to return reviews originally written in
/// the preferred language.
///
/// * For `newest`, reviews are sorted in chronological order; the preferred
/// language does not affect the sort order.
///
/// Google recommends indicating to users whether results are ordered by
/// `most_relevant` or `newest`.
///
/// See [PlaceReview](https://developers.google.com/maps/documentation/places/web-service/search-text#PlaceReview)
/// for more information.
#[serde(default)]
pub reviews: Vec<PlaceReview>,
/// Contains an array of entries for the next seven days including
/// information about secondary hours of a business. Secondary hours are
/// different from a business's main hours. For example, a restaurant can
/// specify drive through hours or delivery hours as its secondary hours.
/// This field populates the type subfield, which draws from a predefined
/// list of opening hours types (such as `DRIVE_THROUGH`, `PICKUP`, or
/// `TAKEOUT`) based on the types of the place. This field includes the
/// `special_days` subfield of all hours, set for dates that have
/// exceptional hours.
///
/// See [PlaceOpeningHours](https://developers.google.com/maps/documentation/places/web-service/search-text#PlaceOpeningHours)
/// for more information.
#[serde(default)]
pub secondary_opening_hours: Option<PlaceOpeningHours>,
/// Specifies if the place serves beer.
#[serde(default)]
pub serves_beer: Option<bool>,
/// Specifies if the place serves breakfast.
#[serde(default)]
pub serves_breakfast: Option<bool>,
/// Specifies if the place serves brunch.
#[serde(default)]
pub serves_brunch: Option<bool>,
/// Specifies if the place serves dinner.
#[serde(default)]
pub serves_dinner: Option<bool>,
/// Specifies if the place serves lunch.
#[serde(default)]
pub serves_lunch: Option<bool>,
/// Specifies if the place serves vegetarian food.
#[serde(default)]
pub serves_vegetarian_food: Option<bool>,
/// Specifies if the place serves wine.
#[serde(default)]
pub serves_wine: Option<bool>,
/// Specifies if the business supports takeout.
#[serde(default)]
pub takeout: Option<bool>,
/// Contains an array of feature types describing the given result. See the
/// list of [supported types](https://developers.google.com/maps/documentation/places/web-service/supported_types#table2).
#[serde(default)]
pub types: Vec<PlaceType>,
/// Contains the URL of the official Google page for this place. This will
/// be the Google-owned page that contains the best available information
/// about the place. Applications must link to or embed this page on any
/// screen that shows detailed results about the place to the user.
#[serde(default)]
pub url: Option<String>,
/// The total number of reviews, with or without text, for this place.
#[serde(default)]
pub user_ratings_total: Option<u64>,
/// Contains the number of minutes this place’s current timezone is offset
/// from UTC. For example, for places in Sydney, Australia during daylight
/// saving time this would be 660 (+11 hours from UTC), and for places in
/// California outside of daylight saving time this would be -480 (-8 hours
/// from UTC).
#[serde(default)]
pub utc_offset: Option<i32>,
/// For establishment (`types:["establishment", ...]`) results only, the
/// `vicinity` field contains a simplified address for the place, including
/// the street name, street number, and locality, but not the
/// province/state, postal code, or country.
///
/// For all other results, the `vicinity` field contains the name of the
/// narrowest political (`types:["political", ...]`) feature that is present
/// in the address of the result.
///
/// This content is meant to be read as-is. Do not programmatically parse
/// the formatted address.
#[serde(default)]
pub vicinity: Option<String>,
/// The authoritative website for this place, such as a business' homepage.
#[serde(default)]
pub website: Option<String>,
/// Specifies if the place has an entrance that is wheelchair-accessible.
#[serde(default)]
pub wheelchair_accessible_entrance: Option<bool>,
} // struct Place
// -----------------------------------------------------------------------------
impl std::str::FromStr for Place {
type Err = serde_json::Error;
/// Parse a Google Maps Places API JSON response into a usable `Place`
/// struct.
fn from_str(s: &str) -> Result<Self, serde_json::Error> {
let bytes = s.to_string().into_bytes();
serde_json::from_slice(&bytes)
} // fn from_str
} // impl FromStr