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::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 Memorystore for Memcached API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_memcache_v1::client::CloudMemcache;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// parent: &str,
29/// ) -> anyhow::Result<()> {
30/// let client = CloudMemcache::builder().build().await?;
31/// let mut list = client.list_instances()
32/// .set_parent(parent)
33/// .by_item();
34/// while let Some(item) = list.next().await.transpose()? {
35/// println!("{:?}", item);
36/// }
37/// Ok(())
38/// }
39/// ```
40///
41/// # Service Description
42///
43/// Configures and manages Cloud Memorystore for Memcached instances.
44///
45/// The `memcache.googleapis.com` service implements the Google Cloud Memorystore
46/// for Memcached API and defines the following resource model for managing
47/// Memorystore Memcached (also called Memcached below) instances:
48///
49/// * The service works with a collection of cloud projects, named: `/projects/*`
50/// * Each project has a collection of available locations, named: `/locations/*`
51/// * Each location has a collection of Memcached instances, named:
52/// `/instances/*`
53/// * As such, Memcached instances are resources of the form:
54/// `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
55///
56/// Note that location_id must be a GCP `region`; for example:
57///
58/// * `projects/my-memcached-project/locations/us-central1/instances/my-memcached`
59///
60/// # Configuration
61///
62/// To configure `CloudMemcache` use the `with_*` methods in the type returned
63/// by [builder()][CloudMemcache::builder]. The default configuration should
64/// work for most applications. Common configuration changes include
65///
66/// * [with_endpoint()]: by default this client uses the global default endpoint
67/// (`https://memcache.googleapis.com`). Applications using regional
68/// endpoints or running in restricted networks (e.g. a network configured
69/// with [Private Google Access with VPC Service Controls]) may want to
70/// override this default.
71/// * [with_credentials()]: by default this client uses
72/// [Application Default Credentials]. Applications using custom
73/// authentication may need to override this default.
74///
75/// [with_endpoint()]: super::builder::cloud_memcache::ClientBuilder::with_endpoint
76/// [with_credentials()]: super::builder::cloud_memcache::ClientBuilder::with_credentials
77/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
78/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
79///
80/// # Pooling and Cloning
81///
82/// `CloudMemcache` holds a connection pool internally, it is advised to
83/// create one and reuse it. You do not need to wrap `CloudMemcache` in
84/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
85/// already uses an `Arc` internally.
86#[derive(Clone, Debug)]
87pub struct CloudMemcache {
88 inner: std::sync::Arc<dyn super::stub::dynamic::CloudMemcache>,
89}
90
91impl CloudMemcache {
92 /// Returns a builder for [CloudMemcache].
93 ///
94 /// ```
95 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
96 /// # use google_cloud_memcache_v1::client::CloudMemcache;
97 /// let client = CloudMemcache::builder().build().await?;
98 /// # Ok(()) }
99 /// ```
100 pub fn builder() -> super::builder::cloud_memcache::ClientBuilder {
101 crate::new_client_builder(super::builder::cloud_memcache::client::Factory)
102 }
103
104 /// Creates a new client from the provided stub.
105 ///
106 /// The most common case for calling this function is in tests mocking the
107 /// client's behavior.
108 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
109 where
110 T: super::stub::CloudMemcache + 'static,
111 {
112 Self { inner: stub.into() }
113 }
114
115 pub(crate) async fn new(
116 config: gaxi::options::ClientConfig,
117 ) -> crate::ClientBuilderResult<Self> {
118 let inner = Self::build_inner(config).await?;
119 Ok(Self { inner })
120 }
121
122 async fn build_inner(
123 conf: gaxi::options::ClientConfig,
124 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::CloudMemcache>> {
125 if gaxi::options::tracing_enabled(&conf) {
126 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
127 }
128 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
129 }
130
131 async fn build_transport(
132 conf: gaxi::options::ClientConfig,
133 ) -> crate::ClientBuilderResult<impl super::stub::CloudMemcache> {
134 super::transport::CloudMemcache::new(conf).await
135 }
136
137 async fn build_with_tracing(
138 conf: gaxi::options::ClientConfig,
139 ) -> crate::ClientBuilderResult<impl super::stub::CloudMemcache> {
140 Self::build_transport(conf)
141 .await
142 .map(super::tracing::CloudMemcache::new)
143 }
144
145 /// Lists Instances in a given location.
146 ///
147 /// # Example
148 /// ```
149 /// # use google_cloud_memcache_v1::client::CloudMemcache;
150 /// use google_cloud_gax::paginator::ItemPaginator as _;
151 /// use google_cloud_memcache_v1::Result;
152 /// async fn sample(
153 /// client: &CloudMemcache, parent: &str
154 /// ) -> Result<()> {
155 /// let mut list = client.list_instances()
156 /// .set_parent(parent)
157 /// .by_item();
158 /// while let Some(item) = list.next().await.transpose()? {
159 /// println!("{:?}", item);
160 /// }
161 /// Ok(())
162 /// }
163 /// ```
164 pub fn list_instances(&self) -> super::builder::cloud_memcache::ListInstances {
165 super::builder::cloud_memcache::ListInstances::new(self.inner.clone())
166 }
167
168 /// Gets details of a single Instance.
169 ///
170 /// # Example
171 /// ```
172 /// # use google_cloud_memcache_v1::client::CloudMemcache;
173 /// use google_cloud_memcache_v1::Result;
174 /// async fn sample(
175 /// client: &CloudMemcache, project_id: &str, location_id: &str, instance_id: &str
176 /// ) -> Result<()> {
177 /// let response = client.get_instance()
178 /// .set_name(format!("projects/{project_id}/locations/{location_id}/instances/{instance_id}"))
179 /// .send().await?;
180 /// println!("response {:?}", response);
181 /// Ok(())
182 /// }
183 /// ```
184 pub fn get_instance(&self) -> super::builder::cloud_memcache::GetInstance {
185 super::builder::cloud_memcache::GetInstance::new(self.inner.clone())
186 }
187
188 /// Creates a new Instance in a given location.
189 ///
190 /// # Long running operations
191 ///
192 /// This method is used to start, and/or poll a [long-running Operation].
193 /// The [Working with long-running operations] chapter in the [user guide]
194 /// covers these operations in detail.
195 ///
196 /// [long-running operation]: https://google.aip.dev/151
197 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
198 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
199 ///
200 /// # Example
201 /// ```
202 /// # use google_cloud_memcache_v1::client::CloudMemcache;
203 /// use google_cloud_lro::Poller;
204 /// use google_cloud_memcache_v1::model::Instance;
205 /// use google_cloud_memcache_v1::Result;
206 /// async fn sample(
207 /// client: &CloudMemcache, parent: &str
208 /// ) -> Result<()> {
209 /// let response = client.create_instance()
210 /// .set_parent(parent)
211 /// .set_instance_id("instance_id_value")
212 /// .set_instance(
213 /// Instance::new()/* set fields */
214 /// )
215 /// .poller().until_done().await?;
216 /// println!("response {:?}", response);
217 /// Ok(())
218 /// }
219 /// ```
220 pub fn create_instance(&self) -> super::builder::cloud_memcache::CreateInstance {
221 super::builder::cloud_memcache::CreateInstance::new(self.inner.clone())
222 }
223
224 /// Updates an existing Instance in a given project and location.
225 ///
226 /// # Long running operations
227 ///
228 /// This method is used to start, and/or poll a [long-running Operation].
229 /// The [Working with long-running operations] chapter in the [user guide]
230 /// covers these operations in detail.
231 ///
232 /// [long-running operation]: https://google.aip.dev/151
233 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
234 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
235 ///
236 /// # Example
237 /// ```
238 /// # use google_cloud_memcache_v1::client::CloudMemcache;
239 /// use google_cloud_lro::Poller;
240 /// # extern crate wkt as google_cloud_wkt;
241 /// use google_cloud_wkt::FieldMask;
242 /// use google_cloud_memcache_v1::model::Instance;
243 /// use google_cloud_memcache_v1::Result;
244 /// async fn sample(
245 /// client: &CloudMemcache, project_id: &str, location_id: &str, instance_id: &str
246 /// ) -> Result<()> {
247 /// let response = client.update_instance()
248 /// .set_instance(
249 /// Instance::new().set_name(format!("projects/{project_id}/locations/{location_id}/instances/{instance_id}"))/* set fields */
250 /// )
251 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
252 /// .poller().until_done().await?;
253 /// println!("response {:?}", response);
254 /// Ok(())
255 /// }
256 /// ```
257 pub fn update_instance(&self) -> super::builder::cloud_memcache::UpdateInstance {
258 super::builder::cloud_memcache::UpdateInstance::new(self.inner.clone())
259 }
260
261 /// Updates the defined Memcached parameters for an existing instance.
262 /// This method only stages the parameters, it must be followed by
263 /// `ApplyParameters` to apply the parameters to nodes of the Memcached
264 /// instance.
265 ///
266 /// # Long running operations
267 ///
268 /// This method is used to start, and/or poll a [long-running Operation].
269 /// The [Working with long-running operations] chapter in the [user guide]
270 /// covers these operations in detail.
271 ///
272 /// [long-running operation]: https://google.aip.dev/151
273 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
274 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
275 ///
276 /// # Example
277 /// ```
278 /// # use google_cloud_memcache_v1::client::CloudMemcache;
279 /// use google_cloud_lro::Poller;
280 /// use google_cloud_memcache_v1::Result;
281 /// async fn sample(
282 /// client: &CloudMemcache
283 /// ) -> Result<()> {
284 /// let response = client.update_parameters()
285 /// /* set fields */
286 /// .poller().until_done().await?;
287 /// println!("response {:?}", response);
288 /// Ok(())
289 /// }
290 /// ```
291 pub fn update_parameters(&self) -> super::builder::cloud_memcache::UpdateParameters {
292 super::builder::cloud_memcache::UpdateParameters::new(self.inner.clone())
293 }
294
295 /// Deletes a single Instance.
296 ///
297 /// # Long running operations
298 ///
299 /// This method is used to start, and/or poll a [long-running Operation].
300 /// The [Working with long-running operations] chapter in the [user guide]
301 /// covers these operations in detail.
302 ///
303 /// [long-running operation]: https://google.aip.dev/151
304 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
305 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
306 ///
307 /// # Example
308 /// ```
309 /// # use google_cloud_memcache_v1::client::CloudMemcache;
310 /// use google_cloud_lro::Poller;
311 /// use google_cloud_memcache_v1::Result;
312 /// async fn sample(
313 /// client: &CloudMemcache, project_id: &str, location_id: &str, instance_id: &str
314 /// ) -> Result<()> {
315 /// client.delete_instance()
316 /// .set_name(format!("projects/{project_id}/locations/{location_id}/instances/{instance_id}"))
317 /// .poller().until_done().await?;
318 /// Ok(())
319 /// }
320 /// ```
321 pub fn delete_instance(&self) -> super::builder::cloud_memcache::DeleteInstance {
322 super::builder::cloud_memcache::DeleteInstance::new(self.inner.clone())
323 }
324
325 /// `ApplyParameters` restarts the set of specified nodes in order to update
326 /// them to the current set of parameters for the Memcached Instance.
327 ///
328 /// # Long running operations
329 ///
330 /// This method is used to start, and/or poll a [long-running Operation].
331 /// The [Working with long-running operations] chapter in the [user guide]
332 /// covers these operations in detail.
333 ///
334 /// [long-running operation]: https://google.aip.dev/151
335 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
336 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
337 ///
338 /// # Example
339 /// ```
340 /// # use google_cloud_memcache_v1::client::CloudMemcache;
341 /// use google_cloud_lro::Poller;
342 /// use google_cloud_memcache_v1::Result;
343 /// async fn sample(
344 /// client: &CloudMemcache
345 /// ) -> Result<()> {
346 /// let response = client.apply_parameters()
347 /// /* set fields */
348 /// .poller().until_done().await?;
349 /// println!("response {:?}", response);
350 /// Ok(())
351 /// }
352 /// ```
353 pub fn apply_parameters(&self) -> super::builder::cloud_memcache::ApplyParameters {
354 super::builder::cloud_memcache::ApplyParameters::new(self.inner.clone())
355 }
356
357 /// Reschedules upcoming maintenance event.
358 ///
359 /// # Long running operations
360 ///
361 /// This method is used to start, and/or poll a [long-running Operation].
362 /// The [Working with long-running operations] chapter in the [user guide]
363 /// covers these operations in detail.
364 ///
365 /// [long-running operation]: https://google.aip.dev/151
366 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
367 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
368 ///
369 /// # Example
370 /// ```
371 /// # use google_cloud_memcache_v1::client::CloudMemcache;
372 /// use google_cloud_lro::Poller;
373 /// use google_cloud_memcache_v1::Result;
374 /// async fn sample(
375 /// client: &CloudMemcache
376 /// ) -> Result<()> {
377 /// let response = client.reschedule_maintenance()
378 /// /* set fields */
379 /// .poller().until_done().await?;
380 /// println!("response {:?}", response);
381 /// Ok(())
382 /// }
383 /// ```
384 pub fn reschedule_maintenance(&self) -> super::builder::cloud_memcache::RescheduleMaintenance {
385 super::builder::cloud_memcache::RescheduleMaintenance::new(self.inner.clone())
386 }
387
388 /// Lists information about the supported locations for this service.
389 ///
390 /// # Example
391 /// ```
392 /// # use google_cloud_memcache_v1::client::CloudMemcache;
393 /// use google_cloud_gax::paginator::ItemPaginator as _;
394 /// use google_cloud_memcache_v1::Result;
395 /// async fn sample(
396 /// client: &CloudMemcache
397 /// ) -> Result<()> {
398 /// let mut list = client.list_locations()
399 /// /* set fields */
400 /// .by_item();
401 /// while let Some(item) = list.next().await.transpose()? {
402 /// println!("{:?}", item);
403 /// }
404 /// Ok(())
405 /// }
406 /// ```
407 pub fn list_locations(&self) -> super::builder::cloud_memcache::ListLocations {
408 super::builder::cloud_memcache::ListLocations::new(self.inner.clone())
409 }
410
411 /// Gets information about a location.
412 ///
413 /// # Example
414 /// ```
415 /// # use google_cloud_memcache_v1::client::CloudMemcache;
416 /// use google_cloud_memcache_v1::Result;
417 /// async fn sample(
418 /// client: &CloudMemcache
419 /// ) -> Result<()> {
420 /// let response = client.get_location()
421 /// /* set fields */
422 /// .send().await?;
423 /// println!("response {:?}", response);
424 /// Ok(())
425 /// }
426 /// ```
427 pub fn get_location(&self) -> super::builder::cloud_memcache::GetLocation {
428 super::builder::cloud_memcache::GetLocation::new(self.inner.clone())
429 }
430
431 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
432 ///
433 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
434 ///
435 /// # Example
436 /// ```
437 /// # use google_cloud_memcache_v1::client::CloudMemcache;
438 /// use google_cloud_gax::paginator::ItemPaginator as _;
439 /// use google_cloud_memcache_v1::Result;
440 /// async fn sample(
441 /// client: &CloudMemcache
442 /// ) -> Result<()> {
443 /// let mut list = client.list_operations()
444 /// /* set fields */
445 /// .by_item();
446 /// while let Some(item) = list.next().await.transpose()? {
447 /// println!("{:?}", item);
448 /// }
449 /// Ok(())
450 /// }
451 /// ```
452 pub fn list_operations(&self) -> super::builder::cloud_memcache::ListOperations {
453 super::builder::cloud_memcache::ListOperations::new(self.inner.clone())
454 }
455
456 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
457 ///
458 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
459 ///
460 /// # Example
461 /// ```
462 /// # use google_cloud_memcache_v1::client::CloudMemcache;
463 /// use google_cloud_memcache_v1::Result;
464 /// async fn sample(
465 /// client: &CloudMemcache
466 /// ) -> Result<()> {
467 /// let response = client.get_operation()
468 /// /* set fields */
469 /// .send().await?;
470 /// println!("response {:?}", response);
471 /// Ok(())
472 /// }
473 /// ```
474 pub fn get_operation(&self) -> super::builder::cloud_memcache::GetOperation {
475 super::builder::cloud_memcache::GetOperation::new(self.inner.clone())
476 }
477
478 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
479 ///
480 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
481 ///
482 /// # Example
483 /// ```
484 /// # use google_cloud_memcache_v1::client::CloudMemcache;
485 /// use google_cloud_memcache_v1::Result;
486 /// async fn sample(
487 /// client: &CloudMemcache
488 /// ) -> Result<()> {
489 /// client.delete_operation()
490 /// /* set fields */
491 /// .send().await?;
492 /// Ok(())
493 /// }
494 /// ```
495 pub fn delete_operation(&self) -> super::builder::cloud_memcache::DeleteOperation {
496 super::builder::cloud_memcache::DeleteOperation::new(self.inner.clone())
497 }
498
499 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
500 ///
501 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
502 ///
503 /// # Example
504 /// ```
505 /// # use google_cloud_memcache_v1::client::CloudMemcache;
506 /// use google_cloud_memcache_v1::Result;
507 /// async fn sample(
508 /// client: &CloudMemcache
509 /// ) -> Result<()> {
510 /// client.cancel_operation()
511 /// /* set fields */
512 /// .send().await?;
513 /// Ok(())
514 /// }
515 /// ```
516 pub fn cancel_operation(&self) -> super::builder::cloud_memcache::CancelOperation {
517 super::builder::cloud_memcache::CancelOperation::new(self.inner.clone())
518 }
519}