Skip to main content

google_maps_geocode_v4/
client.rs

1// Copyright 2026 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Geocoding API.
22///
23/// # Example
24/// ```
25/// # use google_maps_geocode_v4::client::DestinationService;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28///     let client = DestinationService::builder().build().await?;
29///     let response = client.search_destinations()
30///         /* set fields */
31///         .send().await?;
32///     println!("response {:?}", response);
33///     Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// A service for retrieving destinations.
40///
41/// A destination provides hierarchical context about a place, which
42/// allows you to, for example, find apartment buildings within a larger
43/// apartment complex and vice versa. It also provides navigation points suitable
44/// for use cases such as ridesharing or delivery.
45///
46/// # Configuration
47///
48/// To configure `DestinationService` use the `with_*` methods in the type returned
49/// by [builder()][DestinationService::builder]. The default configuration should
50/// work for most applications. Common configuration changes include
51///
52/// * [with_endpoint()]: by default this client uses the global default endpoint
53///   (`https://geocoding-backend.googleapis.com`). Applications using regional
54///   endpoints or running in restricted networks (e.g. a network configured
55///   with [Private Google Access with VPC Service Controls]) may want to
56///   override this default.
57/// * [with_credentials()]: by default this client uses
58///   [Application Default Credentials]. Applications using custom
59///   authentication may need to override this default.
60///
61/// [with_endpoint()]: super::builder::destination_service::ClientBuilder::with_endpoint
62/// [with_credentials()]: super::builder::destination_service::ClientBuilder::with_credentials
63/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
64/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
65///
66/// # Pooling and Cloning
67///
68/// `DestinationService` holds a connection pool internally, it is advised to
69/// create one and reuse it. You do not need to wrap `DestinationService` in
70/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
71/// already uses an `Arc` internally.
72#[derive(Clone, Debug)]
73pub struct DestinationService {
74    inner: std::sync::Arc<dyn super::stub::dynamic::DestinationService>,
75}
76
77impl DestinationService {
78    /// Returns a builder for [DestinationService].
79    ///
80    /// ```
81    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82    /// # use google_maps_geocode_v4::client::DestinationService;
83    /// let client = DestinationService::builder().build().await?;
84    /// # Ok(()) }
85    /// ```
86    pub fn builder() -> super::builder::destination_service::ClientBuilder {
87        crate::new_client_builder(super::builder::destination_service::client::Factory)
88    }
89
90    /// Creates a new client from the provided stub.
91    ///
92    /// The most common case for calling this function is in tests mocking the
93    /// client's behavior.
94    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
95    where
96        T: super::stub::DestinationService + 'static,
97    {
98        Self { inner: stub.into() }
99    }
100
101    pub(crate) async fn new(
102        config: gaxi::options::ClientConfig,
103    ) -> crate::ClientBuilderResult<Self> {
104        let inner = Self::build_inner(config).await?;
105        Ok(Self { inner })
106    }
107
108    async fn build_inner(
109        conf: gaxi::options::ClientConfig,
110    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DestinationService>>
111    {
112        if gaxi::options::tracing_enabled(&conf) {
113            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
114        }
115        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
116    }
117
118    async fn build_transport(
119        conf: gaxi::options::ClientConfig,
120    ) -> crate::ClientBuilderResult<impl super::stub::DestinationService> {
121        super::transport::DestinationService::new(conf).await
122    }
123
124    async fn build_with_tracing(
125        conf: gaxi::options::ClientConfig,
126    ) -> crate::ClientBuilderResult<impl super::stub::DestinationService> {
127        Self::build_transport(conf)
128            .await
129            .map(super::tracing::DestinationService::new)
130    }
131
132    /// This method performs a destination lookup and returns a list of
133    /// destinations.
134    ///
135    /// # Example
136    /// ```
137    /// # use google_maps_geocode_v4::client::DestinationService;
138    /// use google_maps_geocode_v4::Result;
139    /// async fn sample(
140    ///    client: &DestinationService
141    /// ) -> Result<()> {
142    ///     let response = client.search_destinations()
143    ///         /* set fields */
144    ///         .send().await?;
145    ///     println!("response {:?}", response);
146    ///     Ok(())
147    /// }
148    /// ```
149    pub fn search_destinations(&self) -> super::builder::destination_service::SearchDestinations {
150        super::builder::destination_service::SearchDestinations::new(self.inner.clone())
151    }
152}
153
154/// Implements a client for the Geocoding API.
155///
156/// # Example
157/// ```
158/// # use google_maps_geocode_v4::client::GeocodeService;
159/// async fn sample(
160/// ) -> anyhow::Result<()> {
161///     let client = GeocodeService::builder().build().await?;
162///     let response = client.geocode_address()
163///         /* set fields */
164///         .send().await?;
165///     println!("response {:?}", response);
166///     Ok(())
167/// }
168/// ```
169///
170/// # Service Description
171///
172/// A service for performing geocoding.
173///
174/// # Configuration
175///
176/// To configure `GeocodeService` use the `with_*` methods in the type returned
177/// by [builder()][GeocodeService::builder]. The default configuration should
178/// work for most applications. Common configuration changes include
179///
180/// * [with_endpoint()]: by default this client uses the global default endpoint
181///   (`https://geocoding-backend.googleapis.com`). Applications using regional
182///   endpoints or running in restricted networks (e.g. a network configured
183///   with [Private Google Access with VPC Service Controls]) may want to
184///   override this default.
185/// * [with_credentials()]: by default this client uses
186///   [Application Default Credentials]. Applications using custom
187///   authentication may need to override this default.
188///
189/// [with_endpoint()]: super::builder::geocode_service::ClientBuilder::with_endpoint
190/// [with_credentials()]: super::builder::geocode_service::ClientBuilder::with_credentials
191/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
192/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
193///
194/// # Pooling and Cloning
195///
196/// `GeocodeService` holds a connection pool internally, it is advised to
197/// create one and reuse it. You do not need to wrap `GeocodeService` in
198/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
199/// already uses an `Arc` internally.
200#[derive(Clone, Debug)]
201pub struct GeocodeService {
202    inner: std::sync::Arc<dyn super::stub::dynamic::GeocodeService>,
203}
204
205impl GeocodeService {
206    /// Returns a builder for [GeocodeService].
207    ///
208    /// ```
209    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
210    /// # use google_maps_geocode_v4::client::GeocodeService;
211    /// let client = GeocodeService::builder().build().await?;
212    /// # Ok(()) }
213    /// ```
214    pub fn builder() -> super::builder::geocode_service::ClientBuilder {
215        crate::new_client_builder(super::builder::geocode_service::client::Factory)
216    }
217
218    /// Creates a new client from the provided stub.
219    ///
220    /// The most common case for calling this function is in tests mocking the
221    /// client's behavior.
222    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
223    where
224        T: super::stub::GeocodeService + 'static,
225    {
226        Self { inner: stub.into() }
227    }
228
229    pub(crate) async fn new(
230        config: gaxi::options::ClientConfig,
231    ) -> crate::ClientBuilderResult<Self> {
232        let inner = Self::build_inner(config).await?;
233        Ok(Self { inner })
234    }
235
236    async fn build_inner(
237        conf: gaxi::options::ClientConfig,
238    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::GeocodeService>> {
239        if gaxi::options::tracing_enabled(&conf) {
240            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
241        }
242        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
243    }
244
245    async fn build_transport(
246        conf: gaxi::options::ClientConfig,
247    ) -> crate::ClientBuilderResult<impl super::stub::GeocodeService> {
248        super::transport::GeocodeService::new(conf).await
249    }
250
251    async fn build_with_tracing(
252        conf: gaxi::options::ClientConfig,
253    ) -> crate::ClientBuilderResult<impl super::stub::GeocodeService> {
254        Self::build_transport(conf)
255            .await
256            .map(super::tracing::GeocodeService::new)
257    }
258
259    /// This method performs an address geocode, which maps an address to a
260    /// LatLng. It also provides structured information about the address.
261    ///
262    /// # Example
263    /// ```
264    /// # use google_maps_geocode_v4::client::GeocodeService;
265    /// use google_maps_geocode_v4::Result;
266    /// async fn sample(
267    ///    client: &GeocodeService
268    /// ) -> Result<()> {
269    ///     let response = client.geocode_address()
270    ///         /* set fields */
271    ///         .send().await?;
272    ///     println!("response {:?}", response);
273    ///     Ok(())
274    /// }
275    /// ```
276    pub fn geocode_address(&self) -> super::builder::geocode_service::GeocodeAddress {
277        super::builder::geocode_service::GeocodeAddress::new(self.inner.clone())
278    }
279
280    /// This method performs a location geocode, which maps a LatLng to an
281    /// address. It also provides structured information about the address.
282    ///
283    /// # Example
284    /// ```
285    /// # use google_maps_geocode_v4::client::GeocodeService;
286    /// use google_maps_geocode_v4::Result;
287    /// async fn sample(
288    ///    client: &GeocodeService
289    /// ) -> Result<()> {
290    ///     let response = client.geocode_location()
291    ///         /* set fields */
292    ///         .send().await?;
293    ///     println!("response {:?}", response);
294    ///     Ok(())
295    /// }
296    /// ```
297    pub fn geocode_location(&self) -> super::builder::geocode_service::GeocodeLocation {
298        super::builder::geocode_service::GeocodeLocation::new(self.inner.clone())
299    }
300
301    /// This method performs a geocode lookup using a place ID.
302    ///
303    /// # Example
304    /// ```
305    /// # use google_maps_geocode_v4::client::GeocodeService;
306    /// use google_maps_geocode_v4::Result;
307    /// async fn sample(
308    ///    client: &GeocodeService
309    /// ) -> Result<()> {
310    ///     let response = client.geocode_place()
311    ///         /* set fields */
312    ///         .send().await?;
313    ///     println!("response {:?}", response);
314    ///     Ok(())
315    /// }
316    /// ```
317    pub fn geocode_place(&self) -> super::builder::geocode_service::GeocodePlace {
318        super::builder::geocode_service::GeocodePlace::new(self.inner.clone())
319    }
320}