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