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