google_cloud_memcache_v1/
client.rs

1// Copyright 2025 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 Memorystore for Memcached API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_memcache_v1::client::CloudMemcache;
25/// let client = CloudMemcache::builder().build().await?;
26/// // use `client` to make requests to the Cloud Memorystore for Memcached API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Configures and manages Cloud Memorystore for Memcached instances.
33///
34/// The `memcache.googleapis.com` service implements the Google Cloud Memorystore
35/// for Memcached API and defines the following resource model for managing
36/// Memorystore Memcached (also called Memcached below) instances:
37///
38/// * The service works with a collection of cloud projects, named: `/projects/*`
39/// * Each project has a collection of available locations, named: `/locations/*`
40/// * Each location has a collection of Memcached instances, named:
41///   `/instances/*`
42/// * As such, Memcached instances are resources of the form:
43///   `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
44///
45/// Note that location_id must be a GCP `region`; for example:
46///
47/// * `projects/my-memcached-project/locations/us-central1/instances/my-memcached`
48///
49/// # Configuration
50///
51/// To configure `CloudMemcache` use the `with_*` methods in the type returned
52/// by [builder()][CloudMemcache::builder]. The default configuration should
53/// work for most applications. Common configuration changes include
54///
55/// * [with_endpoint()]: by default this client uses the global default endpoint
56///   (`https://memcache.googleapis.com`). Applications using regional
57///   endpoints or running in restricted networks (e.g. a network configured
58//    with [Private Google Access with VPC Service Controls]) may want to
59///   override this default.
60/// * [with_credentials()]: by default this client uses
61///   [Application Default Credentials]. Applications using custom
62///   authentication may need to override this default.
63///
64/// [with_endpoint()]: super::builder::cloud_memcache::ClientBuilder::with_endpoint
65/// [with_credentials()]: super::builder::cloud_memcache::ClientBuilder::credentials
66/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
67/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
68///
69/// # Pooling and Cloning
70///
71/// `CloudMemcache` holds a connection pool internally, it is advised to
72/// create one and the reuse it.  You do not need to wrap `CloudMemcache` in
73/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
74/// already uses an `Arc` internally.
75#[derive(Clone, Debug)]
76pub struct CloudMemcache {
77    inner: std::sync::Arc<dyn super::stub::dynamic::CloudMemcache>,
78}
79
80impl CloudMemcache {
81    /// Returns a builder for [CloudMemcache].
82    ///
83    /// ```
84    /// # tokio_test::block_on(async {
85    /// # use google_cloud_memcache_v1::client::CloudMemcache;
86    /// let client = CloudMemcache::builder().build().await?;
87    /// # gax::client_builder::Result::<()>::Ok(()) });
88    /// ```
89    pub fn builder() -> super::builder::cloud_memcache::ClientBuilder {
90        gax::client_builder::internal::new_builder(super::builder::cloud_memcache::client::Factory)
91    }
92
93    /// Creates a new client from the provided stub.
94    ///
95    /// The most common case for calling this function is in tests mocking the
96    /// client's behavior.
97    pub fn from_stub<T>(stub: T) -> Self
98    where
99        T: super::stub::CloudMemcache + 'static,
100    {
101        Self {
102            inner: std::sync::Arc::new(stub),
103        }
104    }
105
106    pub(crate) async fn new(
107        config: gaxi::options::ClientConfig,
108    ) -> gax::client_builder::Result<Self> {
109        let inner = Self::build_inner(config).await?;
110        Ok(Self { inner })
111    }
112
113    async fn build_inner(
114        conf: gaxi::options::ClientConfig,
115    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::CloudMemcache>> {
116        if gaxi::options::tracing_enabled(&conf) {
117            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
118        }
119        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
120    }
121
122    async fn build_transport(
123        conf: gaxi::options::ClientConfig,
124    ) -> gax::client_builder::Result<impl super::stub::CloudMemcache> {
125        super::transport::CloudMemcache::new(conf).await
126    }
127
128    async fn build_with_tracing(
129        conf: gaxi::options::ClientConfig,
130    ) -> gax::client_builder::Result<impl super::stub::CloudMemcache> {
131        Self::build_transport(conf)
132            .await
133            .map(super::tracing::CloudMemcache::new)
134    }
135
136    /// Lists Instances in a given location.
137    pub fn list_instances(&self) -> super::builder::cloud_memcache::ListInstances {
138        super::builder::cloud_memcache::ListInstances::new(self.inner.clone())
139    }
140
141    /// Gets details of a single Instance.
142    pub fn get_instance(&self) -> super::builder::cloud_memcache::GetInstance {
143        super::builder::cloud_memcache::GetInstance::new(self.inner.clone())
144    }
145
146    /// Creates a new Instance in a given location.
147    ///
148    /// # Long running operations
149    ///
150    /// This method is used to start, and/or poll a [long-running Operation].
151    /// The [Working with long-running operations] chapter in the [user guide]
152    /// covers these operations in detail.
153    ///
154    /// [long-running operation]: https://google.aip.dev/151
155    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
156    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
157    pub fn create_instance(&self) -> super::builder::cloud_memcache::CreateInstance {
158        super::builder::cloud_memcache::CreateInstance::new(self.inner.clone())
159    }
160
161    /// Updates an existing Instance in a given project and location.
162    ///
163    /// # Long running operations
164    ///
165    /// This method is used to start, and/or poll a [long-running Operation].
166    /// The [Working with long-running operations] chapter in the [user guide]
167    /// covers these operations in detail.
168    ///
169    /// [long-running operation]: https://google.aip.dev/151
170    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
171    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
172    pub fn update_instance(&self) -> super::builder::cloud_memcache::UpdateInstance {
173        super::builder::cloud_memcache::UpdateInstance::new(self.inner.clone())
174    }
175
176    /// Updates the defined Memcached parameters for an existing instance.
177    /// This method only stages the parameters, it must be followed by
178    /// `ApplyParameters` to apply the parameters to nodes of the Memcached
179    /// instance.
180    ///
181    /// # Long running operations
182    ///
183    /// This method is used to start, and/or poll a [long-running Operation].
184    /// The [Working with long-running operations] chapter in the [user guide]
185    /// covers these operations in detail.
186    ///
187    /// [long-running operation]: https://google.aip.dev/151
188    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
189    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
190    pub fn update_parameters(&self) -> super::builder::cloud_memcache::UpdateParameters {
191        super::builder::cloud_memcache::UpdateParameters::new(self.inner.clone())
192    }
193
194    /// Deletes a single Instance.
195    ///
196    /// # Long running operations
197    ///
198    /// This method is used to start, and/or poll a [long-running Operation].
199    /// The [Working with long-running operations] chapter in the [user guide]
200    /// covers these operations in detail.
201    ///
202    /// [long-running operation]: https://google.aip.dev/151
203    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
204    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
205    pub fn delete_instance(&self) -> super::builder::cloud_memcache::DeleteInstance {
206        super::builder::cloud_memcache::DeleteInstance::new(self.inner.clone())
207    }
208
209    /// `ApplyParameters` restarts the set of specified nodes in order to update
210    /// them to the current set of parameters for the Memcached Instance.
211    ///
212    /// # Long running operations
213    ///
214    /// This method is used to start, and/or poll a [long-running Operation].
215    /// The [Working with long-running operations] chapter in the [user guide]
216    /// covers these operations in detail.
217    ///
218    /// [long-running operation]: https://google.aip.dev/151
219    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
220    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
221    pub fn apply_parameters(&self) -> super::builder::cloud_memcache::ApplyParameters {
222        super::builder::cloud_memcache::ApplyParameters::new(self.inner.clone())
223    }
224
225    /// Reschedules upcoming maintenance event.
226    ///
227    /// # Long running operations
228    ///
229    /// This method is used to start, and/or poll a [long-running Operation].
230    /// The [Working with long-running operations] chapter in the [user guide]
231    /// covers these operations in detail.
232    ///
233    /// [long-running operation]: https://google.aip.dev/151
234    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
235    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
236    pub fn reschedule_maintenance(&self) -> super::builder::cloud_memcache::RescheduleMaintenance {
237        super::builder::cloud_memcache::RescheduleMaintenance::new(self.inner.clone())
238    }
239
240    /// Lists information about the supported locations for this service.
241    pub fn list_locations(&self) -> super::builder::cloud_memcache::ListLocations {
242        super::builder::cloud_memcache::ListLocations::new(self.inner.clone())
243    }
244
245    /// Gets information about a location.
246    pub fn get_location(&self) -> super::builder::cloud_memcache::GetLocation {
247        super::builder::cloud_memcache::GetLocation::new(self.inner.clone())
248    }
249
250    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
251    ///
252    /// [google.longrunning.Operations]: longrunning::client::Operations
253    pub fn list_operations(&self) -> super::builder::cloud_memcache::ListOperations {
254        super::builder::cloud_memcache::ListOperations::new(self.inner.clone())
255    }
256
257    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
258    ///
259    /// [google.longrunning.Operations]: longrunning::client::Operations
260    pub fn get_operation(&self) -> super::builder::cloud_memcache::GetOperation {
261        super::builder::cloud_memcache::GetOperation::new(self.inner.clone())
262    }
263
264    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
265    ///
266    /// [google.longrunning.Operations]: longrunning::client::Operations
267    pub fn delete_operation(&self) -> super::builder::cloud_memcache::DeleteOperation {
268        super::builder::cloud_memcache::DeleteOperation::new(self.inner.clone())
269    }
270
271    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
272    ///
273    /// [google.longrunning.Operations]: longrunning::client::Operations
274    pub fn cancel_operation(&self) -> super::builder::cloud_memcache::CancelOperation {
275        super::builder::cloud_memcache::CancelOperation::new(self.inner.clone())
276    }
277}