Request

Struct Request 

Source
pub struct Request<'a> { /* private fields */ }
Expand description

Look at this Request struct for documentation on how to build your Time Zone API query. The methods implemented for this struct are what’s used to build your request.

Implementations§

Source§

impl<'r> Request<'r>

Source

pub fn build(&'r mut self) -> Result<&'r mut Self, Error>

👎Deprecated since 3.8.0: try using the query_string method instead

Builds the URL query string for the HTTP GET request.

§Arguments

This method accepts no arguments.

§Notes
  • The query string is the part of the URL after the ? question mark. For example, in the URL https://example.com/over/there?name=ferret the query string is name=ferret

  • The build method has been removed. It would store the generated query string inside of the request structure.

    This way, the same query string would only have to be generated once and could be used for any subsequent retries. This increased implementation complexity but had very performance little benefit. It has been removed.

    If you want to generate a query string (without the preceding URL), try the query_string method.

Source§

impl<'r> Request<'r>

Source

pub const fn new( client: &'r Client, location: LatLng, timestamp: DateTime<Utc>, ) -> Self

Initializes the builder pattern for a Time Zone API query with the required, non-optional parameters.

§Arguments
  • client ‧ Your application’s Google Maps API client struct.

  • location ‧ Latitude & longitude of the desired time zone location.

  • timestamp ‧ Time is used to determine if Daylight Savings is applicable.

§Example
use google_maps::prelude::TimeZoneRequest;
use google_maps::{LatLng, NaiveDate};

let time_zone = TimeZoneRequest::new(
    &my_settings,
    // St. Vitus Cathedral in Prague, Czechia
    LatLng::try_from_dec(50.090_903, 14.400_512)?,
    // Tuesday February 15, 2022 @ 6:00:00 pm
    NaiveDate::from_ymd(2022, 2, 15).and_hms(18, 00, 0)
).execute();
Source§

impl Request<'_>

Source

pub fn with_language(self, language: impl Into<Language>) -> Self

Adds the language parameter to the Time Zone API query.

§Arguments
  • language ‧ The language that Google’s response should be presented in.
§Example
  • Set Google’s response to the French language:
.with_language(Language::French)
Source§

impl Request<'_>

Source

pub async fn execute(self) -> Result<Response, Error>

Executes the Google Maps Time Zone API request.

§Description

This method will:

  1. Validate the request struct that has been built,

  2. Build a URL and query string for an HTTP GET request,

  3. Perform the HTTP GET request using the reqwest crate.

§Arguments

This method accepts no arguments.

§Errors

This method can fail if:

  • This can fail if the request struct fails validation. For example, parameters in the request conflict with one another, or the request parameters are set in a way that’s incompatible.

    For example, Google Maps Directions API cannot calculate alternative routes if waypoints have been set. This will cause a validation failure.

  • The HTTP client cannot make a connection to the Google Maps API server, or successfully send the request or receive the resposne over the network.

  • The Google Maps API server returns an unexpected response, or data in a format that’s not expected.

Source§

impl Request<'_>

Source

pub async fn get(self) -> Result<Response, Error>

👎Deprecated since 3.8.0: try using execute instead

Performs the HTTP get request and returns the response.

§Arguments

This method accepts no arguments.

§Notes
  • The get method for this request has been moved to a get method that’s been generically implemented for all APIs and services, implemented on the google_maps::Client struct.

    Try using execute method for a somewhat similar result. The main difference is that the execute method will validate the request and build the URL string, whereas the previous get implementation (that’s been deprecated) would blindly submit the request, if any.

Trait Implementations§

Source§

impl<'a> Debug for Request<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EndPoint for Request<'_>

Defines a Google Maps API HTTP end-point for a request.

This trait returns information needed to make connect HTTP GET requests to their API end-point. It also includes some extra information for debugging and rating-limiting.

Source§

fn service_url() -> &'static str

URL for the HTTP end-point. For example, https://maps.googleapis.com/maps/api/directions. This string will be used to build the HTTP requests.
Source§

fn title() -> &'static str

Title of the API request end-point. For example Directions API or Elevation API. This title will be output in tracing messages.
Source§

fn apis() -> &'static [Api]

Returns which APIs are being used. This is used for rate-limiting on an API-basis.
Source§

fn output_format() -> Option<&'static str>

Google Maps accepts xml and json formats. Currently, this crate only supports the json format and this function should only return json for now.
Source§

impl QueryString for Request<'_>

Source§

fn query_string(&self) -> String

Builds the URL query string for the HTTP GET request. The query string is generated from the data found in this Request structure.

§Arguments

This method accepts no arguments.

§Notes
  • This function does not validate the request before generating the query string. However, the superior method that generates the query URL does perform validation.

  • The query string is the part of the URL after the ? question mark. For example, in the URL https://example.com/over/there?name=ferret the query string is name=ferret

  • There’s no benefit to working on an owned Request struct (i.e. an owned self versus an borrowed &self). percent-encoding works on borrowed UTF-8 strings. Other types, such as enums and numeric values are converted into strings. Therefore no zero-copy operations are possible with an owned self.

Source§

impl RequestHeaders for Request<'_>

Source§

fn request_headers(&self) -> HeaderMap

Returns a map of HTTP header names to values.

These headers will be added to the HTTP request alongside the standard headers like Content-Type.

This API end-point does not use headers so it returns an empty hash map.

Source§

fn send_x_goog_api_key() -> bool

Returns whether the X-Goog-Api-Key header should be set for this request.

Source§

impl Validatable for Request<'_>

Source§

fn validate(&self) -> Result<(), Error>

Ensures that the request is valid.

§Arguments

This method accepts no arguments.

§Errors
  • This trait implementation is required for operation but there are currently no validations performed for this request type. This method will always return Ok.

Auto Trait Implementations§

§

impl<'a> Freeze for Request<'a>

§

impl<'a> !RefUnwindSafe for Request<'a>

§

impl<'a> Send for Request<'a>

§

impl<'a> Sync for Request<'a>

§

impl<'a> Unpin for Request<'a>

§

impl<'a> !UnwindSafe for Request<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> QueryUrl for T

Source§

fn query_url(&self) -> Result<String, Error>

Returns the URL query string that represents the request you’ve built.

§Description

Returns the URL that will be used as the query to the Google Maps API.

It is the result of the request builder pattern.

This method can also be useful for records or logging. It can also be used for passing to your HTTP client of choice and executing the HTTP GET request yourself.

§Arguments

This method accepts no arguments.

§Errors
  • This can fail if the request struct fails validation. For example, parameters in the request conflict with one another, or the request parameters are set in a way that’s incompatible.

    For example, Google Maps Directions API cannot calculate alternative routes if waypoints have been set. This will cause a validation failure.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T