google_maps_addressvalidation_v1/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 Address Validation API.
22///
23/// # Example
24/// ```
25/// # use google_maps_addressvalidation_v1::client::AddressValidation;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28/// let client = AddressValidation::builder().build().await?;
29/// let response = client.validate_address()
30/// /* set fields */
31/// .send().await?;
32/// println!("response {:?}", response);
33/// Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// The service for validating addresses.
40///
41/// # Configuration
42///
43/// To configure `AddressValidation` use the `with_*` methods in the type returned
44/// by [builder()][AddressValidation::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48/// (`https://addressvalidation.googleapis.com`). Applications using regional
49/// endpoints or running in restricted networks (e.g. a network configured
50/// with [Private Google Access with VPC Service Controls]) may want to
51/// override this default.
52/// * [with_credentials()]: by default this client uses
53/// [Application Default Credentials]. Applications using custom
54/// authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::address_validation::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::address_validation::ClientBuilder::with_credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `AddressValidation` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `AddressValidation` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct AddressValidation {
69 inner: std::sync::Arc<dyn super::stub::dynamic::AddressValidation>,
70}
71
72impl AddressValidation {
73 /// Returns a builder for [AddressValidation].
74 ///
75 /// ```
76 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77 /// # use google_maps_addressvalidation_v1::client::AddressValidation;
78 /// let client = AddressValidation::builder().build().await?;
79 /// # Ok(()) }
80 /// ```
81 pub fn builder() -> super::builder::address_validation::ClientBuilder {
82 crate::new_client_builder(super::builder::address_validation::client::Factory)
83 }
84
85 /// Creates a new client from the provided stub.
86 ///
87 /// The most common case for calling this function is in tests mocking the
88 /// client's behavior.
89 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
90 where
91 T: super::stub::AddressValidation + 'static,
92 {
93 Self { inner: stub.into() }
94 }
95
96 pub(crate) async fn new(
97 config: gaxi::options::ClientConfig,
98 ) -> crate::ClientBuilderResult<Self> {
99 let inner = Self::build_inner(config).await?;
100 Ok(Self { inner })
101 }
102
103 async fn build_inner(
104 conf: gaxi::options::ClientConfig,
105 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::AddressValidation>>
106 {
107 if gaxi::options::tracing_enabled(&conf) {
108 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
109 }
110 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
111 }
112
113 async fn build_transport(
114 conf: gaxi::options::ClientConfig,
115 ) -> crate::ClientBuilderResult<impl super::stub::AddressValidation> {
116 super::transport::AddressValidation::new(conf).await
117 }
118
119 async fn build_with_tracing(
120 conf: gaxi::options::ClientConfig,
121 ) -> crate::ClientBuilderResult<impl super::stub::AddressValidation> {
122 Self::build_transport(conf)
123 .await
124 .map(super::tracing::AddressValidation::new)
125 }
126
127 /// Validates an address.
128 ///
129 /// # Example
130 /// ```
131 /// # use google_maps_addressvalidation_v1::client::AddressValidation;
132 /// use google_maps_addressvalidation_v1::Result;
133 /// async fn sample(
134 /// client: &AddressValidation
135 /// ) -> Result<()> {
136 /// let response = client.validate_address()
137 /// /* set fields */
138 /// .send().await?;
139 /// println!("response {:?}", response);
140 /// Ok(())
141 /// }
142 /// ```
143 pub fn validate_address(&self) -> super::builder::address_validation::ValidateAddress {
144 super::builder::address_validation::ValidateAddress::new(self.inner.clone())
145 }
146
147 /// Feedback about the outcome of the sequence of validation attempts. This
148 /// should be the last call made after a sequence of validation calls for the
149 /// same address, and should be called once the transaction is concluded. This
150 /// should only be sent once for the sequence of `ValidateAddress` requests
151 /// needed to validate an address fully.
152 ///
153 /// # Example
154 /// ```
155 /// # use google_maps_addressvalidation_v1::client::AddressValidation;
156 /// use google_maps_addressvalidation_v1::Result;
157 /// async fn sample(
158 /// client: &AddressValidation
159 /// ) -> Result<()> {
160 /// let response = client.provide_validation_feedback()
161 /// /* set fields */
162 /// .send().await?;
163 /// println!("response {:?}", response);
164 /// Ok(())
165 /// }
166 /// ```
167 pub fn provide_validation_feedback(
168 &self,
169 ) -> super::builder::address_validation::ProvideValidationFeedback {
170 super::builder::address_validation::ProvideValidationFeedback::new(self.inner.clone())
171 }
172}