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