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
19use crate::Result;
20
21/// Implements a client for the Cloud Metadata API.
22///
23/// # Example
24/// ```
25/// # tokio_test::block_on(async {
26/// # use google_cloud_location::client::Locations;
27/// let client = Locations::builder().build().await?;
28/// // use `client` to make requests to the Cloud Metadata API.
29/// # gax::Result::<()>::Ok(()) });
30/// ```
31///
32/// # Service Description
33///
34/// An abstract interface that provides location-related information for
35/// a service. Service-specific metadata is provided through the
36/// [Location.metadata][google.cloud.location.Location.metadata] field.
37///
38/// [google.cloud.location.Location.metadata]: crate::model::Location::metadata
39///
40/// # Configuration
41///
42/// To configure `Locations` use the `with_*` methods in the type returned
43/// by [builder()][Locations::builder]. The default configuration should
44/// work for most applications. Common configuration changes include
45///
46/// * [with_endpoint()]: by default this client uses the global default endpoint
47/// (`https://cloud.googleapis.com`). Applications using regional
48/// endpoints or running in restricted networks (e.g. a network configured
49// with [Private Google Access with VPC Service Controls]) may want to
50/// override this default.
51/// * [with_credentials()]: by default this client uses
52/// [Application Default Credentials]. Applications using custom
53/// authentication may need to override this default.
54///
55/// [with_endpoint()]: super::builder::locations::ClientBuilder::with_endpoint
56/// [with_credentials()]: super::builder::locations::ClientBuilder::credentials
57/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
58/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
59///
60/// # Pooling and Cloning
61///
62/// `Locations` holds a connection pool internally, it is advised to
63/// create one and the reuse it. You do not need to wrap `Locations` in
64/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
65/// already uses an `Arc` internally.
66#[derive(Clone, Debug)]
67pub struct Locations {
68 inner: std::sync::Arc<dyn super::stub::dynamic::Locations>,
69}
70
71impl Locations {
72 /// Returns a builder for [Locations].
73 ///
74 /// ```
75 /// # tokio_test::block_on(async {
76 /// # use google_cloud_location::client::Locations;
77 /// let client = Locations::builder().build().await?;
78 /// # gax::Result::<()>::Ok(()) });
79 /// ```
80 pub fn builder() -> super::builder::locations::ClientBuilder {
81 gax::client_builder::internal::new_builder(super::builder::locations::client::Factory)
82 }
83
84 /// Creates a new client from the provided stub.
85 ///
86 /// The most common case for calling this function is in tests mocking the
87 /// client's behavior.
88 pub fn from_stub<T>(stub: T) -> Self
89 where
90 T: super::stub::Locations + 'static,
91 {
92 Self {
93 inner: std::sync::Arc::new(stub),
94 }
95 }
96
97 pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
98 let inner = Self::build_inner(config).await?;
99 Ok(Self { inner })
100 }
101
102 async fn build_inner(
103 conf: gaxi::options::ClientConfig,
104 ) -> Result<std::sync::Arc<dyn super::stub::dynamic::Locations>> {
105 if gaxi::options::tracing_enabled(&conf) {
106 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
107 }
108 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
109 }
110
111 async fn build_transport(
112 conf: gaxi::options::ClientConfig,
113 ) -> Result<impl super::stub::Locations> {
114 super::transport::Locations::new(conf).await
115 }
116
117 async fn build_with_tracing(
118 conf: gaxi::options::ClientConfig,
119 ) -> Result<impl super::stub::Locations> {
120 Self::build_transport(conf)
121 .await
122 .map(super::tracing::Locations::new)
123 }
124
125 /// Lists information about the supported locations for this service.
126 pub fn list_locations(&self) -> super::builder::locations::ListLocations {
127 super::builder::locations::ListLocations::new(self.inner.clone())
128 }
129
130 /// Gets information about a location.
131 pub fn get_location(&self) -> super::builder::locations::GetLocation {
132 super::builder::locations::GetLocation::new(self.inner.clone())
133 }
134}