[][src]Struct google_maps::request_rate::RequestRate

pub struct RequestRate {
    pub all: Option<ApiRate>,
    pub directions: Option<ApiRate>,
    pub distance_matrix: Option<ApiRate>,
    pub elevation: Option<ApiRate>,
    pub geocoding: Option<ApiRate>,
    pub time_zone: Option<ApiRate>,
}

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]

Specifies the request rate for the selected API.

Arguments:

  • api ‧ API on which to apply the request rate limit. The argument may be Api::All which is evaluated in addition to each of the per-API (i.e. Api::Directions or Api::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 the std::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)
)
.with_rate(Api::Elevation, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
.with_rate(Api::Geocoding, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))
.with_rate(Api::TimeZone, (GOOGLE_CREDIT / 0.005) as u16, from_secs(SECONDS_PER_MONTH))

Trait Implementations

impl Clone for RequestRate[src]

impl Debug for RequestRate[src]

impl Default for RequestRate[src]

fn default() -> Self[src]

Returns a reasonable default values for the RequestRate struct.

impl Eq for RequestRate[src]

impl Ord for RequestRate[src]

impl PartialEq<RequestRate> for RequestRate[src]

impl PartialOrd<RequestRate> for RequestRate[src]

impl StructuralEq for RequestRate[src]

impl StructuralPartialEq for RequestRate[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,