[−][src]Struct google_maps::request_rate::RequestRate
Contains the request rates for the Google Maps Platform and the individual Google Maps APIs.
Fields
all: Option<ApiRate>
Used to specify the request rate for all APIs in addition to the
per-API request rates. The Api::All
request rate will be observed
first, then the per-API request rate such as Api::Directions
will be
observed afterward.
directions: Option<ApiRate>
distance_matrix: Option<ApiRate>
elevation: Option<ApiRate>
geocoding: Option<ApiRate>
time_zone: Option<ApiRate>
Methods
impl RequestRate
[src]
pub fn limit(&mut self, api: Api)
[src]
This method is not for public consumption. It is for internal use only.
Description
This method does the actual rate limiting. It will look up the actual effective requests/duration rate and compare it to the targeted requests/duration rate. If the current rate exceeds the targeted rate, this method will put the thread to sleep until it is ready for the next request.
Arguments:
api
‧ The API for which to observe the request rate limit.
impl RequestRate
[src]
pub fn with_rate(
&mut self,
api: Api,
requests: u16,
duration: Duration
) -> &mut RequestRate
[src]
&mut self,
api: Api,
requests: u16,
duration: Duration
) -> &mut RequestRate
Specifies the request rate for the selected API.
Arguments:
-
api
‧ API on which to apply the request rate limit. The argument may beApi::All
which is evaluated in addition to each of the per-API (i.e.Api::Directions
orApi::Elevation
) request rate limits. -
requests
‧ The number of requests the client library is attempting to target. -
duration
‧ The duration for the targeted request rate. For example this field may define requests per second, per minute, per day, and so on. This can be defined using thestd::time::Duration
methods.
Examples:
The following examples show how one might try to limit the request rate to achieve maximum throughput while minimizing charges by Google.
The following rates are subject to change by Google. Please review the current Google Maps Platform billing rates.
This Google client library's rate limiting is not persistent. If your program is often restarted, it is easily possible to exceed Google's monthly free credit. These are approximations and examples.
To accurately minimize billing charges by Google, please use the Google Cloud Platform Console IAM & admin to set quotas for each API on the server's side.
You are responsible for all charges. Use with care.
// Assumptions: // - $200.00 USD monthly free credit from Google. Thanks, guys! // - 2,629,746 seconds in a month. const GOOGLE_CREDIT: f64 = 200.0; const SECONDS_PER_MONTH: u64 = 2_629_746;
- Directions API. You are billed for this SKU when your request does not use traffic information, arrival or departure times, < 10 waypoints, and no waypoint optimization, $0.005 USD per request.
.with_rate(Api::Directions, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
- Directions Advanced API. You are billed for this SKU when your request requires include traffic information, > 10 waypoints, and/or waypoint optimization, $0.01 per request.
.with_rate(Api::Directions, (GOOGLE_CREDIT / 0.01) as u16, from_secs(SECONDS_PER_MONTH))
- Distance Matrix API. You are billed for this SKU when your requests does not require traffic information, $0.005 per element. The below rate assumes an average of 10 elements per request.
.with_rate( Api::Directions, (GOOGLE_CREDIT / (0.005 * 10.0)) as u16, from_secs(SECONDS_PER_MONTH) )
- Distance Matrix Advanced API. You are billed for this SKU when your requests require traffic information, $0.01 USD per element. The below rate assumes an average of 10 elements per request.
.with_rate( Api::DistanceMatrix, (GOOGLE_CREDIT / (0.01 * 10.0)) as u16, from_secs(SECONDS_PER_MONTH) )
- Elevation API. $0.005 USD per request.
.with_rate(Api::Elevation, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
- Geocoding API. $0.005 USD per request.
.with_rate(Api::Geocoding, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
- Time Zone API. $0.005 USD per request.
.with_rate(Api::TimeZone, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
Trait Implementations
impl Clone for RequestRate
[src]
fn clone(&self) -> RequestRate
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for RequestRate
[src]
impl Default for RequestRate
[src]
impl Eq for RequestRate
[src]
impl Ord for RequestRate
[src]
fn cmp(&self, other: &RequestRate) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<RequestRate> for RequestRate
[src]
fn eq(&self, other: &RequestRate) -> bool
[src]
fn ne(&self, other: &RequestRate) -> bool
[src]
impl PartialOrd<RequestRate> for RequestRate
[src]
fn partial_cmp(&self, other: &RequestRate) -> Option<Ordering>
[src]
fn lt(&self, other: &RequestRate) -> bool
[src]
fn le(&self, other: &RequestRate) -> bool
[src]
fn gt(&self, other: &RequestRate) -> bool
[src]
fn ge(&self, other: &RequestRate) -> bool
[src]
impl StructuralEq for RequestRate
[src]
impl StructuralPartialEq for RequestRate
[src]
Auto Trait Implementations
impl RefUnwindSafe for RequestRate
impl Send for RequestRate
impl Sync for RequestRate
impl Unpin for RequestRate
impl UnwindSafe for RequestRate
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,