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>
impl<'r> Request<'r>
Sourcepub fn build(&'r mut self) -> Result<&'r mut Self, Error>
👎Deprecated since 3.8.0: try using the query_string method instead
pub fn build(&'r mut self) -> Result<&'r mut Self, Error>
query_string method insteadBuilds 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 URLhttps://example.com/over/there?name=ferretthe query string isname=ferret -
The
buildmethod 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_stringmethod.
Source§impl<'r> Request<'r>
impl<'r> Request<'r>
Sourcepub const fn new(
client: &'r Client,
location: LatLng,
timestamp: DateTime<Utc>,
) -> Self
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<'_>
impl Request<'_>
Sourcepub async fn execute(self) -> Result<Response, Error>
pub async fn execute(self) -> Result<Response, Error>
Executes the Google Maps Time Zone API request.
§Description
This method will:
-
Validate the request
structthat has been built, -
Build a URL and query string for an HTTP GET request,
§Arguments
This method accepts no arguments.
§Errors
This method can fail if:
-
This can fail if the request
structfails 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<'_>
impl Request<'_>
Sourcepub async fn get(self) -> Result<Response, Error>
👎Deprecated since 3.8.0: try using execute instead
pub async fn get(self) -> Result<Response, Error>
execute insteadPerforms the HTTP get request and returns the response.
§Arguments
This method accepts no arguments.
§Notes
-
The
getmethod for this request has been moved to agetmethod that’s been generically implemented for all APIs and services, implemented on thegoogle_maps::Clientstruct.Try using
executemethod for a somewhat similar result. The main difference is that the execute method will validate the request and build the URL string, whereas the previousgetimplementation (that’s been deprecated) would blindly submit the request, if any.
Trait Implementations§
Source§impl EndPoint for Request<'_>
Defines a Google Maps API HTTP end-point for a request.
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
fn service_url() -> &'static str
https://maps.googleapis.com/maps/api/directions. This string will be
used to build the HTTP requests.Source§fn title() -> &'static str
fn title() -> &'static str
Directions API or
Elevation API. This title will be output in tracing messages.Source§fn apis() -> &'static [Api]
fn apis() -> &'static [Api]
Source§fn output_format() -> Option<&'static str>
fn output_format() -> Option<&'static str>
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<'_>
impl QueryString for Request<'_>
Source§fn query_string(&self) -> String
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 URLhttps://example.com/over/there?name=ferretthe query string isname=ferret -
There’s no benefit to working on an owned
Requeststruct (i.e. an ownedselfversus 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 ownedself.
Source§impl RequestHeaders for Request<'_>
impl RequestHeaders for Request<'_>
Source§fn request_headers(&self) -> HeaderMap
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
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<'_>
impl Validatable for Request<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> QueryUrl for T
impl<T> QueryUrl for T
Source§fn query_url(&self) -> Result<String, Error>
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
structfails 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.