Skip to main content

google_cloud_pubsub/generated/gapic/
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 Pub/Sub API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_pubsub::client::TopicAdmin;
24/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
25///     let client = TopicAdmin::builder().build().await?;
26///     let topic = "topic_value";
27///     let response = client.get_topic()
28///         .set_topic(topic)
29///         .send().await?;
30///     println!("response {:?}", response);
31/// # Ok(()) }
32/// ```
33///
34/// # Service Description
35///
36/// The service that an application uses to manipulate topics.
37///
38/// # Configuration
39///
40/// To configure `TopicAdmin` use the `with_*` methods in the type returned
41/// by [builder()][TopicAdmin::builder]. The default configuration should
42/// work for most applications. Common configuration changes include
43///
44/// * [with_endpoint()]: by default this client uses the global default endpoint
45///   (`https://pubsub.googleapis.com`). Applications using regional
46///   endpoints or running in restricted networks (e.g. a network configured
47//    with [Private Google Access with VPC Service Controls]) may want to
48///   override this default.
49/// * [with_credentials()]: by default this client uses
50///   [Application Default Credentials]. Applications using custom
51///   authentication may need to override this default.
52///
53/// [with_endpoint()]: super::builder::topic_admin::ClientBuilder::with_endpoint
54/// [with_credentials()]: super::builder::topic_admin::ClientBuilder::with_credentials
55/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
56/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
57///
58/// # Pooling and Cloning
59///
60/// `TopicAdmin` holds a connection pool internally, it is advised to
61/// create one and reuse it. You do not need to wrap `TopicAdmin` in
62/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
63/// already uses an `Arc` internally.
64#[derive(Clone, Debug)]
65pub struct TopicAdmin {
66    inner: std::sync::Arc<dyn super::stub::dynamic::TopicAdmin>,
67}
68
69impl TopicAdmin {
70    /// Returns a builder for [TopicAdmin].
71    ///
72    /// ```
73    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
74    /// # use google_cloud_pubsub::client::TopicAdmin;
75    /// let client = TopicAdmin::builder().build().await?;
76    /// # Ok(()) }
77    /// ```
78    pub fn builder() -> super::builder::topic_admin::ClientBuilder {
79        crate::new_client_builder(super::builder::topic_admin::client::Factory)
80    }
81
82    /// Creates a new client from the provided stub.
83    ///
84    /// The most common case for calling this function is in tests mocking the
85    /// client's behavior.
86    pub fn from_stub<T>(stub: T) -> Self
87    where
88        T: super::stub::TopicAdmin + 'static,
89    {
90        Self {
91            inner: std::sync::Arc::new(stub),
92        }
93    }
94
95    pub(crate) async fn new(
96        config: gaxi::options::ClientConfig,
97    ) -> crate::ClientBuilderResult<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    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::TopicAdmin>> {
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    ) -> crate::ClientBuilderResult<impl super::stub::TopicAdmin> {
114        super::transport::TopicAdmin::new(conf).await
115    }
116
117    async fn build_with_tracing(
118        conf: gaxi::options::ClientConfig,
119    ) -> crate::ClientBuilderResult<impl super::stub::TopicAdmin> {
120        Self::build_transport(conf)
121            .await
122            .map(super::tracing::TopicAdmin::new)
123    }
124
125    /// Creates the given topic with the given name. See the [resource name rules]
126    /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>).
127    ///
128    /// # Example
129    /// ```
130    /// # use google_cloud_pubsub::client::TopicAdmin;
131    /// use google_cloud_pubsub::Result;
132    /// async fn sample(
133    ///    client: &TopicAdmin
134    /// ) -> Result<()> {
135    ///     let response = client.create_topic()
136    ///         /* set fields */
137    ///         .send().await?;
138    ///     println!("response {:?}", response);
139    ///     Ok(())
140    /// }
141    /// ```
142    pub fn create_topic(&self) -> super::builder::topic_admin::CreateTopic {
143        super::builder::topic_admin::CreateTopic::new(self.inner.clone())
144    }
145
146    /// Updates an existing topic by updating the fields specified in the update
147    /// mask. Note that certain properties of a topic are not modifiable.
148    ///
149    /// # Example
150    /// ```
151    /// # use google_cloud_pubsub::client::TopicAdmin;
152    /// # extern crate wkt as google_cloud_wkt;
153    /// use google_cloud_wkt::FieldMask;
154    /// use google_cloud_pubsub::model::Topic;
155    /// use google_cloud_pubsub::Result;
156    /// async fn sample(
157    ///    client: &TopicAdmin, name: &str
158    /// ) -> Result<()> {
159    ///     let response = client.update_topic()
160    ///         .set_topic(
161    ///             Topic::new().set_name(name)/* set fields */
162    ///         )
163    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
164    ///         .send().await?;
165    ///     println!("response {:?}", response);
166    ///     Ok(())
167    /// }
168    /// ```
169    pub fn update_topic(&self) -> super::builder::topic_admin::UpdateTopic {
170        super::builder::topic_admin::UpdateTopic::new(self.inner.clone())
171    }
172
173    /// Gets the configuration of a topic.
174    ///
175    /// # Example
176    /// ```
177    /// # use google_cloud_pubsub::client::TopicAdmin;
178    /// use google_cloud_pubsub::Result;
179    /// async fn sample(
180    ///    client: &TopicAdmin, topic: &str
181    /// ) -> Result<()> {
182    ///     let response = client.get_topic()
183    ///         .set_topic(topic)
184    ///         .send().await?;
185    ///     println!("response {:?}", response);
186    ///     Ok(())
187    /// }
188    /// ```
189    pub fn get_topic(&self) -> super::builder::topic_admin::GetTopic {
190        super::builder::topic_admin::GetTopic::new(self.inner.clone())
191    }
192
193    /// Lists matching topics.
194    ///
195    /// # Example
196    /// ```
197    /// # use google_cloud_pubsub::client::TopicAdmin;
198    /// use google_cloud_gax::paginator::ItemPaginator as _;
199    /// use google_cloud_pubsub::Result;
200    /// async fn sample(
201    ///    client: &TopicAdmin
202    /// ) -> Result<()> {
203    ///     let mut list = client.list_topics()
204    ///         /* set fields */
205    ///         .by_item();
206    ///     while let Some(item) = list.next().await.transpose()? {
207    ///         println!("{:?}", item);
208    ///     }
209    ///     Ok(())
210    /// }
211    /// ```
212    pub fn list_topics(&self) -> super::builder::topic_admin::ListTopics {
213        super::builder::topic_admin::ListTopics::new(self.inner.clone())
214    }
215
216    /// Lists the names of the attached subscriptions on this topic.
217    ///
218    /// # Example
219    /// ```
220    /// # use google_cloud_pubsub::client::TopicAdmin;
221    /// use google_cloud_gax::paginator::ItemPaginator as _;
222    /// use google_cloud_pubsub::Result;
223    /// async fn sample(
224    ///    client: &TopicAdmin
225    /// ) -> Result<()> {
226    ///     let mut list = client.list_topic_subscriptions()
227    ///         /* set fields */
228    ///         .by_item();
229    ///     while let Some(item) = list.next().await.transpose()? {
230    ///         println!("{:?}", item);
231    ///     }
232    ///     Ok(())
233    /// }
234    /// ```
235    pub fn list_topic_subscriptions(&self) -> super::builder::topic_admin::ListTopicSubscriptions {
236        super::builder::topic_admin::ListTopicSubscriptions::new(self.inner.clone())
237    }
238
239    /// Lists the names of the snapshots on this topic. Snapshots are used in
240    /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
241    /// which allow you to manage message acknowledgments in bulk. That is, you can
242    /// set the acknowledgment state of messages in an existing subscription to the
243    /// state captured by a snapshot.
244    ///
245    /// # Example
246    /// ```
247    /// # use google_cloud_pubsub::client::TopicAdmin;
248    /// use google_cloud_pubsub::Result;
249    /// async fn sample(
250    ///    client: &TopicAdmin
251    /// ) -> Result<()> {
252    ///     let response = client.list_topic_snapshots()
253    ///         /* set fields */
254    ///         .send().await?;
255    ///     println!("response {:?}", response);
256    ///     Ok(())
257    /// }
258    /// ```
259    pub fn list_topic_snapshots(&self) -> super::builder::topic_admin::ListTopicSnapshots {
260        super::builder::topic_admin::ListTopicSnapshots::new(self.inner.clone())
261    }
262
263    /// Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
264    /// does not exist. After a topic is deleted, a new topic may be created with
265    /// the same name; this is an entirely new topic with none of the old
266    /// configuration or subscriptions. Existing subscriptions to this topic are
267    /// not deleted, but their `topic` field is set to `_deleted-topic_`.
268    ///
269    /// # Example
270    /// ```
271    /// # use google_cloud_pubsub::client::TopicAdmin;
272    /// use google_cloud_pubsub::Result;
273    /// async fn sample(
274    ///    client: &TopicAdmin, topic: &str
275    /// ) -> Result<()> {
276    ///     client.delete_topic()
277    ///         .set_topic(topic)
278    ///         .send().await?;
279    ///     Ok(())
280    /// }
281    /// ```
282    pub fn delete_topic(&self) -> super::builder::topic_admin::DeleteTopic {
283        super::builder::topic_admin::DeleteTopic::new(self.inner.clone())
284    }
285
286    /// Detaches a subscription from this topic. All messages retained in the
287    /// subscription are dropped. Subsequent `Pull` and `StreamingPull` requests
288    /// will return FAILED_PRECONDITION. If the subscription is a push
289    /// subscription, pushes to the endpoint will stop.
290    ///
291    /// # Example
292    /// ```
293    /// # use google_cloud_pubsub::client::TopicAdmin;
294    /// use google_cloud_pubsub::Result;
295    /// async fn sample(
296    ///    client: &TopicAdmin
297    /// ) -> Result<()> {
298    ///     let response = client.detach_subscription()
299    ///         /* set fields */
300    ///         .send().await?;
301    ///     println!("response {:?}", response);
302    ///     Ok(())
303    /// }
304    /// ```
305    pub fn detach_subscription(&self) -> super::builder::topic_admin::DetachSubscription {
306        super::builder::topic_admin::DetachSubscription::new(self.inner.clone())
307    }
308}
309
310/// Implements a client for the Cloud Pub/Sub API.
311///
312/// # Example
313/// ```
314/// # use google_cloud_pubsub::client::SubscriptionAdmin;
315/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
316///     let client = SubscriptionAdmin::builder().build().await?;
317///     let subscription = "subscription_value";
318///     let response = client.get_subscription()
319///         .set_subscription(subscription)
320///         .send().await?;
321///     println!("response {:?}", response);
322/// # Ok(()) }
323/// ```
324///
325/// # Service Description
326///
327/// The service that an application uses to manipulate subscriptions.
328///
329/// # Configuration
330///
331/// To configure `SubscriptionAdmin` use the `with_*` methods in the type returned
332/// by [builder()][SubscriptionAdmin::builder]. The default configuration should
333/// work for most applications. Common configuration changes include
334///
335/// * [with_endpoint()]: by default this client uses the global default endpoint
336///   (`https://pubsub.googleapis.com`). Applications using regional
337///   endpoints or running in restricted networks (e.g. a network configured
338//    with [Private Google Access with VPC Service Controls]) may want to
339///   override this default.
340/// * [with_credentials()]: by default this client uses
341///   [Application Default Credentials]. Applications using custom
342///   authentication may need to override this default.
343///
344/// [with_endpoint()]: super::builder::subscription_admin::ClientBuilder::with_endpoint
345/// [with_credentials()]: super::builder::subscription_admin::ClientBuilder::with_credentials
346/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
347/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
348///
349/// # Pooling and Cloning
350///
351/// `SubscriptionAdmin` holds a connection pool internally, it is advised to
352/// create one and reuse it. You do not need to wrap `SubscriptionAdmin` in
353/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
354/// already uses an `Arc` internally.
355#[derive(Clone, Debug)]
356pub struct SubscriptionAdmin {
357    inner: std::sync::Arc<dyn super::stub::dynamic::SubscriptionAdmin>,
358}
359
360impl SubscriptionAdmin {
361    /// Returns a builder for [SubscriptionAdmin].
362    ///
363    /// ```
364    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
365    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
366    /// let client = SubscriptionAdmin::builder().build().await?;
367    /// # Ok(()) }
368    /// ```
369    pub fn builder() -> super::builder::subscription_admin::ClientBuilder {
370        crate::new_client_builder(super::builder::subscription_admin::client::Factory)
371    }
372
373    /// Creates a new client from the provided stub.
374    ///
375    /// The most common case for calling this function is in tests mocking the
376    /// client's behavior.
377    pub fn from_stub<T>(stub: T) -> Self
378    where
379        T: super::stub::SubscriptionAdmin + 'static,
380    {
381        Self {
382            inner: std::sync::Arc::new(stub),
383        }
384    }
385
386    pub(crate) async fn new(
387        config: gaxi::options::ClientConfig,
388    ) -> crate::ClientBuilderResult<Self> {
389        let inner = Self::build_inner(config).await?;
390        Ok(Self { inner })
391    }
392
393    async fn build_inner(
394        conf: gaxi::options::ClientConfig,
395    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::SubscriptionAdmin>>
396    {
397        if gaxi::options::tracing_enabled(&conf) {
398            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
399        }
400        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
401    }
402
403    async fn build_transport(
404        conf: gaxi::options::ClientConfig,
405    ) -> crate::ClientBuilderResult<impl super::stub::SubscriptionAdmin> {
406        super::transport::SubscriptionAdmin::new(conf).await
407    }
408
409    async fn build_with_tracing(
410        conf: gaxi::options::ClientConfig,
411    ) -> crate::ClientBuilderResult<impl super::stub::SubscriptionAdmin> {
412        Self::build_transport(conf)
413            .await
414            .map(super::tracing::SubscriptionAdmin::new)
415    }
416
417    /// Creates a subscription to a given topic. See the [resource name rules]
418    /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>).
419    /// If the subscription already exists, returns `ALREADY_EXISTS`.
420    /// If the corresponding topic doesn't exist, returns `NOT_FOUND`.
421    ///
422    /// If the name is not provided in the request, the server will assign a random
423    /// name for this subscription on the same project as the topic, conforming
424    /// to the [resource name format]
425    /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>). The
426    /// generated name is populated in the returned Subscription object. Note that
427    /// for REST API requests, you must specify a name in the request.
428    ///
429    /// # Example
430    /// ```
431    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
432    /// use google_cloud_pubsub::Result;
433    /// async fn sample(
434    ///    client: &SubscriptionAdmin
435    /// ) -> Result<()> {
436    ///     let response = client.create_subscription()
437    ///         /* set fields */
438    ///         .send().await?;
439    ///     println!("response {:?}", response);
440    ///     Ok(())
441    /// }
442    /// ```
443    pub fn create_subscription(&self) -> super::builder::subscription_admin::CreateSubscription {
444        super::builder::subscription_admin::CreateSubscription::new(self.inner.clone())
445    }
446
447    /// Gets the configuration details of a subscription.
448    ///
449    /// # Example
450    /// ```
451    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
452    /// use google_cloud_pubsub::Result;
453    /// async fn sample(
454    ///    client: &SubscriptionAdmin, subscription: &str
455    /// ) -> Result<()> {
456    ///     let response = client.get_subscription()
457    ///         .set_subscription(subscription)
458    ///         .send().await?;
459    ///     println!("response {:?}", response);
460    ///     Ok(())
461    /// }
462    /// ```
463    pub fn get_subscription(&self) -> super::builder::subscription_admin::GetSubscription {
464        super::builder::subscription_admin::GetSubscription::new(self.inner.clone())
465    }
466
467    /// Updates an existing subscription by updating the fields specified in the
468    /// update mask. Note that certain properties of a subscription, such as its
469    /// topic, are not modifiable.
470    ///
471    /// # Example
472    /// ```
473    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
474    /// # extern crate wkt as google_cloud_wkt;
475    /// use google_cloud_wkt::FieldMask;
476    /// use google_cloud_pubsub::model::Subscription;
477    /// use google_cloud_pubsub::Result;
478    /// async fn sample(
479    ///    client: &SubscriptionAdmin, name: &str
480    /// ) -> Result<()> {
481    ///     let response = client.update_subscription()
482    ///         .set_subscription(
483    ///             Subscription::new().set_name(name)/* set fields */
484    ///         )
485    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
486    ///         .send().await?;
487    ///     println!("response {:?}", response);
488    ///     Ok(())
489    /// }
490    /// ```
491    pub fn update_subscription(&self) -> super::builder::subscription_admin::UpdateSubscription {
492        super::builder::subscription_admin::UpdateSubscription::new(self.inner.clone())
493    }
494
495    /// Lists matching subscriptions.
496    ///
497    /// # Example
498    /// ```
499    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
500    /// use google_cloud_gax::paginator::ItemPaginator as _;
501    /// use google_cloud_pubsub::Result;
502    /// async fn sample(
503    ///    client: &SubscriptionAdmin
504    /// ) -> Result<()> {
505    ///     let mut list = client.list_subscriptions()
506    ///         /* set fields */
507    ///         .by_item();
508    ///     while let Some(item) = list.next().await.transpose()? {
509    ///         println!("{:?}", item);
510    ///     }
511    ///     Ok(())
512    /// }
513    /// ```
514    pub fn list_subscriptions(&self) -> super::builder::subscription_admin::ListSubscriptions {
515        super::builder::subscription_admin::ListSubscriptions::new(self.inner.clone())
516    }
517
518    /// Deletes an existing subscription. All messages retained in the subscription
519    /// are immediately dropped. Calls to `Pull` after deletion will return
520    /// `NOT_FOUND`. After a subscription is deleted, a new one may be created with
521    /// the same name, but the new one has no association with the old
522    /// subscription or its topic unless the same topic is specified.
523    ///
524    /// # Example
525    /// ```
526    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
527    /// use google_cloud_pubsub::Result;
528    /// async fn sample(
529    ///    client: &SubscriptionAdmin, subscription: &str
530    /// ) -> Result<()> {
531    ///     client.delete_subscription()
532    ///         .set_subscription(subscription)
533    ///         .send().await?;
534    ///     Ok(())
535    /// }
536    /// ```
537    pub fn delete_subscription(&self) -> super::builder::subscription_admin::DeleteSubscription {
538        super::builder::subscription_admin::DeleteSubscription::new(self.inner.clone())
539    }
540
541    /// Modifies the `PushConfig` for a specified subscription.
542    ///
543    /// This may be used to change a push subscription to a pull one (signified by
544    /// an empty `PushConfig`) or vice versa, or change the endpoint URL and other
545    /// attributes of a push subscription. Messages will accumulate for delivery
546    /// continuously through the call regardless of changes to the `PushConfig`.
547    ///
548    /// # Example
549    /// ```
550    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
551    /// use google_cloud_pubsub::Result;
552    /// async fn sample(
553    ///    client: &SubscriptionAdmin
554    /// ) -> Result<()> {
555    ///     client.modify_push_config()
556    ///         /* set fields */
557    ///         .send().await?;
558    ///     Ok(())
559    /// }
560    /// ```
561    pub fn modify_push_config(&self) -> super::builder::subscription_admin::ModifyPushConfig {
562        super::builder::subscription_admin::ModifyPushConfig::new(self.inner.clone())
563    }
564
565    /// Gets the configuration details of a snapshot. Snapshots are used in
566    /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
567    /// which allow you to manage message acknowledgments in bulk. That is, you can
568    /// set the acknowledgment state of messages in an existing subscription to the
569    /// state captured by a snapshot.
570    ///
571    /// # Example
572    /// ```
573    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
574    /// use google_cloud_pubsub::Result;
575    /// async fn sample(
576    ///    client: &SubscriptionAdmin, snapshot: &str
577    /// ) -> Result<()> {
578    ///     let response = client.get_snapshot()
579    ///         .set_snapshot(snapshot)
580    ///         .send().await?;
581    ///     println!("response {:?}", response);
582    ///     Ok(())
583    /// }
584    /// ```
585    pub fn get_snapshot(&self) -> super::builder::subscription_admin::GetSnapshot {
586        super::builder::subscription_admin::GetSnapshot::new(self.inner.clone())
587    }
588
589    /// Lists the existing snapshots. Snapshots are used in [Seek](
590    /// <https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
591    /// allow you to manage message acknowledgments in bulk. That is, you can set
592    /// the acknowledgment state of messages in an existing subscription to the
593    /// state captured by a snapshot.
594    ///
595    /// # Example
596    /// ```
597    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
598    /// use google_cloud_gax::paginator::ItemPaginator as _;
599    /// use google_cloud_pubsub::Result;
600    /// async fn sample(
601    ///    client: &SubscriptionAdmin
602    /// ) -> Result<()> {
603    ///     let mut list = client.list_snapshots()
604    ///         /* set fields */
605    ///         .by_item();
606    ///     while let Some(item) = list.next().await.transpose()? {
607    ///         println!("{:?}", item);
608    ///     }
609    ///     Ok(())
610    /// }
611    /// ```
612    pub fn list_snapshots(&self) -> super::builder::subscription_admin::ListSnapshots {
613        super::builder::subscription_admin::ListSnapshots::new(self.inner.clone())
614    }
615
616    /// Creates a snapshot from the requested subscription. Snapshots are used in
617    /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
618    /// which allow you to manage message acknowledgments in bulk. That is, you can
619    /// set the acknowledgment state of messages in an existing subscription to the
620    /// state captured by a snapshot.
621    /// If the snapshot already exists, returns `ALREADY_EXISTS`.
622    /// If the requested subscription doesn't exist, returns `NOT_FOUND`.
623    /// If the backlog in the subscription is too old -- and the resulting snapshot
624    /// would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned.
625    /// See also the `Snapshot.expire_time` field. If the name is not provided in
626    /// the request, the server will assign a random
627    /// name for this snapshot on the same project as the subscription, conforming
628    /// to the [resource name format]
629    /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>). The
630    /// generated name is populated in the returned Snapshot object. Note that for
631    /// REST API requests, you must specify a name in the request.
632    ///
633    /// # Example
634    /// ```
635    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
636    /// use google_cloud_pubsub::Result;
637    /// async fn sample(
638    ///    client: &SubscriptionAdmin
639    /// ) -> Result<()> {
640    ///     let response = client.create_snapshot()
641    ///         /* set fields */
642    ///         .send().await?;
643    ///     println!("response {:?}", response);
644    ///     Ok(())
645    /// }
646    /// ```
647    pub fn create_snapshot(&self) -> super::builder::subscription_admin::CreateSnapshot {
648        super::builder::subscription_admin::CreateSnapshot::new(self.inner.clone())
649    }
650
651    /// Updates an existing snapshot by updating the fields specified in the update
652    /// mask. Snapshots are used in
653    /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
654    /// which allow you to manage message acknowledgments in bulk. That is, you can
655    /// set the acknowledgment state of messages in an existing subscription to the
656    /// state captured by a snapshot.
657    ///
658    /// # Example
659    /// ```
660    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
661    /// # extern crate wkt as google_cloud_wkt;
662    /// use google_cloud_wkt::FieldMask;
663    /// use google_cloud_pubsub::model::Snapshot;
664    /// use google_cloud_pubsub::Result;
665    /// async fn sample(
666    ///    client: &SubscriptionAdmin, name: &str
667    /// ) -> Result<()> {
668    ///     let response = client.update_snapshot()
669    ///         .set_snapshot(
670    ///             Snapshot::new().set_name(name)/* set fields */
671    ///         )
672    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
673    ///         .send().await?;
674    ///     println!("response {:?}", response);
675    ///     Ok(())
676    /// }
677    /// ```
678    pub fn update_snapshot(&self) -> super::builder::subscription_admin::UpdateSnapshot {
679        super::builder::subscription_admin::UpdateSnapshot::new(self.inner.clone())
680    }
681
682    /// Removes an existing snapshot. Snapshots are used in [Seek]
683    /// (<https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
684    /// allow you to manage message acknowledgments in bulk. That is, you can set
685    /// the acknowledgment state of messages in an existing subscription to the
686    /// state captured by a snapshot.
687    /// When the snapshot is deleted, all messages retained in the snapshot
688    /// are immediately dropped. After a snapshot is deleted, a new one may be
689    /// created with the same name, but the new one has no association with the old
690    /// snapshot or its subscription, unless the same subscription is specified.
691    ///
692    /// # Example
693    /// ```
694    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
695    /// use google_cloud_pubsub::Result;
696    /// async fn sample(
697    ///    client: &SubscriptionAdmin, snapshot: &str
698    /// ) -> Result<()> {
699    ///     client.delete_snapshot()
700    ///         .set_snapshot(snapshot)
701    ///         .send().await?;
702    ///     Ok(())
703    /// }
704    /// ```
705    pub fn delete_snapshot(&self) -> super::builder::subscription_admin::DeleteSnapshot {
706        super::builder::subscription_admin::DeleteSnapshot::new(self.inner.clone())
707    }
708
709    /// Seeks an existing subscription to a point in time or to a given snapshot,
710    /// whichever is provided in the request. Snapshots are used in [Seek]
711    /// (<https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
712    /// allow you to manage message acknowledgments in bulk. That is, you can set
713    /// the acknowledgment state of messages in an existing subscription to the
714    /// state captured by a snapshot. Note that both the subscription and the
715    /// snapshot must be on the same topic.
716    ///
717    /// # Example
718    /// ```
719    /// # use google_cloud_pubsub::client::SubscriptionAdmin;
720    /// use google_cloud_pubsub::Result;
721    /// async fn sample(
722    ///    client: &SubscriptionAdmin
723    /// ) -> Result<()> {
724    ///     let response = client.seek()
725    ///         /* set fields */
726    ///         .send().await?;
727    ///     println!("response {:?}", response);
728    ///     Ok(())
729    /// }
730    /// ```
731    pub fn seek(&self) -> super::builder::subscription_admin::Seek {
732        super::builder::subscription_admin::Seek::new(self.inner.clone())
733    }
734}
735
736/// Implements a client for the Cloud Pub/Sub API.
737///
738/// # Example
739/// ```
740/// # use google_cloud_pubsub::client::SchemaService;
741/// use google_cloud_gax::paginator::ItemPaginator as _;
742/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
743///     let client = SchemaService::builder().build().await?;
744///     let parent = "parent_value";
745///     let mut list = client.list_schemas()
746///         .set_parent(parent)
747///         .by_item();
748///     while let Some(item) = list.next().await.transpose()? {
749///         println!("{:?}", item);
750///     }
751/// # Ok(()) }
752/// ```
753///
754/// # Service Description
755///
756/// Service for doing schema-related operations.
757///
758/// # Configuration
759///
760/// To configure `SchemaService` use the `with_*` methods in the type returned
761/// by [builder()][SchemaService::builder]. The default configuration should
762/// work for most applications. Common configuration changes include
763///
764/// * [with_endpoint()]: by default this client uses the global default endpoint
765///   (`https://pubsub.googleapis.com`). Applications using regional
766///   endpoints or running in restricted networks (e.g. a network configured
767//    with [Private Google Access with VPC Service Controls]) may want to
768///   override this default.
769/// * [with_credentials()]: by default this client uses
770///   [Application Default Credentials]. Applications using custom
771///   authentication may need to override this default.
772///
773/// [with_endpoint()]: super::builder::schema_service::ClientBuilder::with_endpoint
774/// [with_credentials()]: super::builder::schema_service::ClientBuilder::with_credentials
775/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
776/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
777///
778/// # Pooling and Cloning
779///
780/// `SchemaService` holds a connection pool internally, it is advised to
781/// create one and reuse it. You do not need to wrap `SchemaService` in
782/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
783/// already uses an `Arc` internally.
784#[derive(Clone, Debug)]
785pub struct SchemaService {
786    inner: std::sync::Arc<dyn super::stub::dynamic::SchemaService>,
787}
788
789impl SchemaService {
790    /// Returns a builder for [SchemaService].
791    ///
792    /// ```
793    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
794    /// # use google_cloud_pubsub::client::SchemaService;
795    /// let client = SchemaService::builder().build().await?;
796    /// # Ok(()) }
797    /// ```
798    pub fn builder() -> super::builder::schema_service::ClientBuilder {
799        crate::new_client_builder(super::builder::schema_service::client::Factory)
800    }
801
802    /// Creates a new client from the provided stub.
803    ///
804    /// The most common case for calling this function is in tests mocking the
805    /// client's behavior.
806    pub fn from_stub<T>(stub: T) -> Self
807    where
808        T: super::stub::SchemaService + 'static,
809    {
810        Self {
811            inner: std::sync::Arc::new(stub),
812        }
813    }
814
815    pub(crate) async fn new(
816        config: gaxi::options::ClientConfig,
817    ) -> crate::ClientBuilderResult<Self> {
818        let inner = Self::build_inner(config).await?;
819        Ok(Self { inner })
820    }
821
822    async fn build_inner(
823        conf: gaxi::options::ClientConfig,
824    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::SchemaService>> {
825        if gaxi::options::tracing_enabled(&conf) {
826            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
827        }
828        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
829    }
830
831    async fn build_transport(
832        conf: gaxi::options::ClientConfig,
833    ) -> crate::ClientBuilderResult<impl super::stub::SchemaService> {
834        super::transport::SchemaService::new(conf).await
835    }
836
837    async fn build_with_tracing(
838        conf: gaxi::options::ClientConfig,
839    ) -> crate::ClientBuilderResult<impl super::stub::SchemaService> {
840        Self::build_transport(conf)
841            .await
842            .map(super::tracing::SchemaService::new)
843    }
844
845    /// Creates a schema.
846    ///
847    /// # Example
848    /// ```
849    /// # use google_cloud_pubsub::client::SchemaService;
850    /// use google_cloud_pubsub::model::Schema;
851    /// use google_cloud_pubsub::Result;
852    /// async fn sample(
853    ///    client: &SchemaService, parent: &str
854    /// ) -> Result<()> {
855    ///     let response = client.create_schema()
856    ///         .set_parent(parent)
857    ///         .set_schema_id("schema_id_value")
858    ///         .set_schema(
859    ///             Schema::new()/* set fields */
860    ///         )
861    ///         .send().await?;
862    ///     println!("response {:?}", response);
863    ///     Ok(())
864    /// }
865    /// ```
866    pub fn create_schema(&self) -> super::builder::schema_service::CreateSchema {
867        super::builder::schema_service::CreateSchema::new(self.inner.clone())
868    }
869
870    /// Gets a schema.
871    ///
872    /// # Example
873    /// ```
874    /// # use google_cloud_pubsub::client::SchemaService;
875    /// use google_cloud_pubsub::Result;
876    /// async fn sample(
877    ///    client: &SchemaService, name: &str
878    /// ) -> Result<()> {
879    ///     let response = client.get_schema()
880    ///         .set_name(name)
881    ///         .send().await?;
882    ///     println!("response {:?}", response);
883    ///     Ok(())
884    /// }
885    /// ```
886    pub fn get_schema(&self) -> super::builder::schema_service::GetSchema {
887        super::builder::schema_service::GetSchema::new(self.inner.clone())
888    }
889
890    /// Lists schemas in a project.
891    ///
892    /// # Example
893    /// ```
894    /// # use google_cloud_pubsub::client::SchemaService;
895    /// use google_cloud_gax::paginator::ItemPaginator as _;
896    /// use google_cloud_pubsub::Result;
897    /// async fn sample(
898    ///    client: &SchemaService, parent: &str
899    /// ) -> Result<()> {
900    ///     let mut list = client.list_schemas()
901    ///         .set_parent(parent)
902    ///         .by_item();
903    ///     while let Some(item) = list.next().await.transpose()? {
904    ///         println!("{:?}", item);
905    ///     }
906    ///     Ok(())
907    /// }
908    /// ```
909    pub fn list_schemas(&self) -> super::builder::schema_service::ListSchemas {
910        super::builder::schema_service::ListSchemas::new(self.inner.clone())
911    }
912
913    /// Lists all schema revisions for the named schema.
914    ///
915    /// # Example
916    /// ```
917    /// # use google_cloud_pubsub::client::SchemaService;
918    /// use google_cloud_gax::paginator::ItemPaginator as _;
919    /// use google_cloud_pubsub::Result;
920    /// async fn sample(
921    ///    client: &SchemaService
922    /// ) -> Result<()> {
923    ///     let mut list = client.list_schema_revisions()
924    ///         /* set fields */
925    ///         .by_item();
926    ///     while let Some(item) = list.next().await.transpose()? {
927    ///         println!("{:?}", item);
928    ///     }
929    ///     Ok(())
930    /// }
931    /// ```
932    pub fn list_schema_revisions(&self) -> super::builder::schema_service::ListSchemaRevisions {
933        super::builder::schema_service::ListSchemaRevisions::new(self.inner.clone())
934    }
935
936    /// Commits a new schema revision to an existing schema.
937    ///
938    /// # Example
939    /// ```
940    /// # use google_cloud_pubsub::client::SchemaService;
941    /// use google_cloud_pubsub::Result;
942    /// async fn sample(
943    ///    client: &SchemaService
944    /// ) -> Result<()> {
945    ///     let response = client.commit_schema()
946    ///         /* set fields */
947    ///         .send().await?;
948    ///     println!("response {:?}", response);
949    ///     Ok(())
950    /// }
951    /// ```
952    pub fn commit_schema(&self) -> super::builder::schema_service::CommitSchema {
953        super::builder::schema_service::CommitSchema::new(self.inner.clone())
954    }
955
956    /// Creates a new schema revision that is a copy of the provided revision_id.
957    ///
958    /// # Example
959    /// ```
960    /// # use google_cloud_pubsub::client::SchemaService;
961    /// use google_cloud_pubsub::Result;
962    /// async fn sample(
963    ///    client: &SchemaService
964    /// ) -> Result<()> {
965    ///     let response = client.rollback_schema()
966    ///         /* set fields */
967    ///         .send().await?;
968    ///     println!("response {:?}", response);
969    ///     Ok(())
970    /// }
971    /// ```
972    pub fn rollback_schema(&self) -> super::builder::schema_service::RollbackSchema {
973        super::builder::schema_service::RollbackSchema::new(self.inner.clone())
974    }
975
976    /// Deletes a specific schema revision.
977    ///
978    /// # Example
979    /// ```
980    /// # use google_cloud_pubsub::client::SchemaService;
981    /// use google_cloud_pubsub::Result;
982    /// async fn sample(
983    ///    client: &SchemaService, name: &str
984    /// ) -> Result<()> {
985    ///     let response = client.delete_schema_revision()
986    ///         .set_name(name)
987    ///         .send().await?;
988    ///     println!("response {:?}", response);
989    ///     Ok(())
990    /// }
991    /// ```
992    pub fn delete_schema_revision(&self) -> super::builder::schema_service::DeleteSchemaRevision {
993        super::builder::schema_service::DeleteSchemaRevision::new(self.inner.clone())
994    }
995
996    /// Deletes a schema.
997    ///
998    /// # Example
999    /// ```
1000    /// # use google_cloud_pubsub::client::SchemaService;
1001    /// use google_cloud_pubsub::Result;
1002    /// async fn sample(
1003    ///    client: &SchemaService, name: &str
1004    /// ) -> Result<()> {
1005    ///     client.delete_schema()
1006    ///         .set_name(name)
1007    ///         .send().await?;
1008    ///     Ok(())
1009    /// }
1010    /// ```
1011    pub fn delete_schema(&self) -> super::builder::schema_service::DeleteSchema {
1012        super::builder::schema_service::DeleteSchema::new(self.inner.clone())
1013    }
1014
1015    /// Validates a schema.
1016    ///
1017    /// # Example
1018    /// ```
1019    /// # use google_cloud_pubsub::client::SchemaService;
1020    /// use google_cloud_pubsub::Result;
1021    /// async fn sample(
1022    ///    client: &SchemaService
1023    /// ) -> Result<()> {
1024    ///     let response = client.validate_schema()
1025    ///         /* set fields */
1026    ///         .send().await?;
1027    ///     println!("response {:?}", response);
1028    ///     Ok(())
1029    /// }
1030    /// ```
1031    pub fn validate_schema(&self) -> super::builder::schema_service::ValidateSchema {
1032        super::builder::schema_service::ValidateSchema::new(self.inner.clone())
1033    }
1034
1035    /// Validates a message against a schema.
1036    ///
1037    /// # Example
1038    /// ```
1039    /// # use google_cloud_pubsub::client::SchemaService;
1040    /// use google_cloud_pubsub::Result;
1041    /// async fn sample(
1042    ///    client: &SchemaService
1043    /// ) -> Result<()> {
1044    ///     let response = client.validate_message()
1045    ///         /* set fields */
1046    ///         .send().await?;
1047    ///     println!("response {:?}", response);
1048    ///     Ok(())
1049    /// }
1050    /// ```
1051    pub fn validate_message(&self) -> super::builder::schema_service::ValidateMessage {
1052        super::builder::schema_service::ValidateMessage::new(self.inner.clone())
1053    }
1054
1055    /// Sets the access control policy on the specified resource. Replaces
1056    /// any existing policy.
1057    ///
1058    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
1059    /// errors.
1060    ///
1061    /// # Example
1062    /// ```
1063    /// # use google_cloud_pubsub::client::SchemaService;
1064    /// use google_cloud_pubsub::Result;
1065    /// async fn sample(
1066    ///    client: &SchemaService
1067    /// ) -> Result<()> {
1068    ///     let response = client.set_iam_policy()
1069    ///         /* set fields */
1070    ///         .send().await?;
1071    ///     println!("response {:?}", response);
1072    ///     Ok(())
1073    /// }
1074    /// ```
1075    pub fn set_iam_policy(&self) -> super::builder::schema_service::SetIamPolicy {
1076        super::builder::schema_service::SetIamPolicy::new(self.inner.clone())
1077    }
1078
1079    /// Gets the access control policy for a resource. Returns an empty policy
1080    /// if the resource exists and does not have a policy set.
1081    ///
1082    /// # Example
1083    /// ```
1084    /// # use google_cloud_pubsub::client::SchemaService;
1085    /// use google_cloud_pubsub::Result;
1086    /// async fn sample(
1087    ///    client: &SchemaService
1088    /// ) -> Result<()> {
1089    ///     let response = client.get_iam_policy()
1090    ///         /* set fields */
1091    ///         .send().await?;
1092    ///     println!("response {:?}", response);
1093    ///     Ok(())
1094    /// }
1095    /// ```
1096    pub fn get_iam_policy(&self) -> super::builder::schema_service::GetIamPolicy {
1097        super::builder::schema_service::GetIamPolicy::new(self.inner.clone())
1098    }
1099
1100    /// Returns permissions that a caller has on the specified resource. If the
1101    /// resource does not exist, this will return an empty set of
1102    /// permissions, not a `NOT_FOUND` error.
1103    ///
1104    /// Note: This operation is designed to be used for building
1105    /// permission-aware UIs and command-line tools, not for authorization
1106    /// checking. This operation may "fail open" without warning.
1107    ///
1108    /// # Example
1109    /// ```
1110    /// # use google_cloud_pubsub::client::SchemaService;
1111    /// use google_cloud_pubsub::Result;
1112    /// async fn sample(
1113    ///    client: &SchemaService
1114    /// ) -> Result<()> {
1115    ///     let response = client.test_iam_permissions()
1116    ///         /* set fields */
1117    ///         .send().await?;
1118    ///     println!("response {:?}", response);
1119    ///     Ok(())
1120    /// }
1121    /// ```
1122    pub fn test_iam_permissions(&self) -> super::builder::schema_service::TestIamPermissions {
1123        super::builder::schema_service::TestIamPermissions::new(self.inner.clone())
1124    }
1125}