google_maps/time_zone/request/
new.rs

1use crate::types::LatLng;
2use chrono::{DateTime, Utc};
3
4// =============================================================================
5
6impl<'r> crate::time_zone::request::Request<'r> {
7    // -------------------------------------------------------------------------
8    //
9    /// Initializes the builder pattern for a Time Zone API query with the
10    /// required, non-optional parameters.
11    ///
12    /// ## Arguments
13    ///
14    /// * `client` ‧ Your application's Google Maps API client struct.
15    ///
16    /// * `location` ‧ Latitude & longitude of the desired time zone location.
17    ///
18    /// * `timestamp` ‧ Time is used to determine if Daylight Savings is
19    ///   applicable.
20    ///
21    /// ## Example
22    ///
23    /// ```rust
24    /// use google_maps::prelude::TimeZoneRequest;
25    /// use google_maps::{LatLng, NaiveDate};
26    ///
27    /// let time_zone = TimeZoneRequest::new(
28    ///     &my_settings,
29    ///     // St. Vitus Cathedral in Prague, Czechia
30    ///     LatLng::try_from_dec(50.090_903, 14.400_512)?,
31    ///     // Tuesday February 15, 2022 @ 6:00:00 pm
32    ///     NaiveDate::from_ymd(2022, 2, 15).and_hms(18, 00, 0)
33    /// ).execute();
34    /// ```
35    #[must_use]
36    pub const fn new(
37        client: &'r crate::Client,
38        location: LatLng,
39        timestamp: DateTime<Utc>
40    ) -> Self {
41        // Instantiate struct and return it to caller:
42        Self {
43            // Required parameters:
44            client,
45            location,
46            timestamp,
47            // Optional parameters:
48            language: None,
49        } // struct
50    } // fn
51
52    // -------------------------------------------------------------------------
53    //
54    /// Initializes the builder pattern for a Time Zone API query with the
55    /// required, non-optional parameters.
56    ///
57    /// This function is the same as `new` but it supports
58    /// the [geo](https://crates.io/crates/geo) crate's
59    /// [Coord](https://docs.rs/geo/latest/geo/geometry/struct.Coord.html) type.
60    ///
61    /// ## Arguments
62    ///
63    /// * `client` ‧ Your application's Google Maps API client struct.
64    /// * `coordinate` - `Coord` of the desired time zone location.
65    /// * `timestamp` - Time is used to determine if Daylight Savings is
66    ///   applicable.
67    #[cfg(feature = "geo")]
68    pub fn try_new_coordinate<'g>(
69        client: &'r crate::Client,
70        coordinate: &'g geo_types::Coord,
71        timestamp: DateTime<Utc>
72    ) -> Result<Self, crate::error::Error> {
73        // Instantiate struct and return it to caller:
74        Ok(Self {
75            // Required parameters:
76            client,
77            location: LatLng::try_from(coordinate)?,
78            timestamp,
79            // Optional parameters:
80            language: None,
81        }) // struct
82    } // fn
83
84    // -------------------------------------------------------------------------
85    //
86    /// Initializes the builder pattern for a Time Zone API query with the
87    /// required, non-optional parameters.
88    ///
89    /// This function is the same as `new` but it supports
90    /// the [geo](https://crates.io/crates/geo) crate's
91    /// [Point](https://docs.rs/geo/latest/geo/geometry/struct.Point.html) type.
92    ///
93    /// ## Arguments
94    ///
95    /// * `client` ‧ Your application's Google Maps API client struct.
96    /// * `point` - `Point` of the desired time zone location.
97    /// * `timestamp` - Time is used to determine if Daylight Savings is
98    ///   applicable.
99    #[cfg(feature = "geo")]
100    pub fn try_new_point<'g>(
101        client: &'r crate::Client,
102        point: &'g geo_types::Point,
103        timestamp: DateTime<Utc>
104    ) -> Result<Self, crate::error::Error> {
105        // Instantiate struct and return it to caller:
106        Ok(Self {
107            // Required parameters:
108            client,
109            location: LatLng::try_from(point)?,
110            timestamp,
111            // Optional parameters:
112            language: None,
113        }) // struct
114    } // fn
115} // impl