google_maps/request_rate/api.rs
1//! Contains the `Api` enum and its associated traits. The `Api` enum is used to
2//! specify a Google Maps Platform API when setting per-API request rate limits.
3
4use serde::{Deserialize, Serialize};
5
6// -----------------------------------------------------------------------------
7//
8/// `Api` is used to select an API to configure. For example, the Google Maps
9/// Client can be set to have different request rates for `Directions` and
10/// `Elevation` requests. This `enum` is used to select which Google Maps API
11/// you would like to configure.
12#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
13#[repr(u8)]
14pub enum Api {
15 /// This variant is used to select settings that are observed for _all_
16 /// APIs. These settings are observed in addition to the per-API settings.
17 All = 0,
18 Directions = 1,
19 DistanceMatrix = 2,
20 Elevation = 3,
21 Geocoding = 4,
22 TimeZone = 5,
23 Roads = 6,
24 AddressValidation = 7,
25 // Places API (Legacy)
26 Places = 8,
27 // Places API (New)
28 PlacesNew = 9,
29 Autocomplete = 10,
30 NearbySearch = 11,
31 PlaceDetails = 12,
32 PlacePhoto = 13,
33 TextSearch = 14,
34} // enum
35
36// -----------------------------------------------------------------------------
37
38impl std::convert::From<&Api> for String {
39 /// Converts an `Api` enum to a `String` that contains an API name.
40 fn from(api: &Api) -> Self {
41 match api {
42 Api::All => Self::from("All"),
43 Api::Directions => Self::from("Directions"),
44 Api::DistanceMatrix => Self::from("Distance Matrix"),
45 Api::Elevation => Self::from("Elevation"),
46 Api::Geocoding => Self::from("Geocoding"),
47 Api::TimeZone => Self::from("Time Zone"),
48 Api::Places => Self::from("Places"),
49 Api::Roads => Self::from("Roads"),
50 Api::AddressValidation => Self::from("Address Validation"),
51 Api::PlacesNew => Self::from("Places (New)"),
52 Api::Autocomplete => Self::from("Autocomplete"),
53 Api::NearbySearch => Self::from("Nearby Search"),
54 Api::PlaceDetails => Self::from("Place Details"),
55 Api::PlacePhoto => Self::from("Place Photo"),
56 Api::TextSearch => Self::from("Text Search"),
57 } // match
58 } // fn
59} // impl
60
61// -----------------------------------------------------------------------------
62
63impl std::default::Default for Api {
64 /// Returns a reasonable default variant for the `Api` enum.
65 fn default() -> Self {
66 Self::All
67 } // fn
68} // impl
69
70// -----------------------------------------------------------------------------
71
72impl std::fmt::Display for Api {
73 /// Formats an `Api` enum into a string that is presentable to the end user.
74 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
75 write!(f, "{}", String::from(self))
76 } // fn
77} // impl