google_cloud_api_serviceusage_v1/
builder.rs1pub mod service_usage {
18 use crate::Result;
19
20 pub type ClientBuilder =
34 gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36 pub(crate) mod client {
37 use super::super::super::client::ServiceUsage;
38 pub struct Factory;
39 impl gax::client_builder::internal::ClientFactory for Factory {
40 type Client = ServiceUsage;
41 type Credentials = gaxi::options::Credentials;
42 async fn build(
43 self,
44 config: gaxi::options::ClientConfig,
45 ) -> gax::client_builder::Result<Self::Client> {
46 Self::Client::new(config).await
47 }
48 }
49 }
50
51 #[derive(Clone, Debug)]
53 pub(crate) struct RequestBuilder<R: std::default::Default> {
54 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
55 request: R,
56 options: gax::options::RequestOptions,
57 }
58
59 impl<R> RequestBuilder<R>
60 where
61 R: std::default::Default,
62 {
63 pub(crate) fn new(
64 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
65 ) -> Self {
66 Self {
67 stub,
68 request: R::default(),
69 options: gax::options::RequestOptions::default(),
70 }
71 }
72 }
73
74 #[derive(Clone, Debug)]
92 pub struct EnableService(RequestBuilder<crate::model::EnableServiceRequest>);
93
94 impl EnableService {
95 pub(crate) fn new(
96 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
97 ) -> Self {
98 Self(RequestBuilder::new(stub))
99 }
100
101 pub fn with_request<V: Into<crate::model::EnableServiceRequest>>(mut self, v: V) -> Self {
103 self.0.request = v.into();
104 self
105 }
106
107 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
109 self.0.options = v.into();
110 self
111 }
112
113 pub async fn send(self) -> Result<longrunning::model::Operation> {
120 (*self.0.stub)
121 .enable_service(self.0.request, self.0.options)
122 .await
123 .map(gax::response::Response::into_body)
124 }
125
126 pub fn poller(
128 self,
129 ) -> impl lro::Poller<crate::model::EnableServiceResponse, crate::model::OperationMetadata>
130 {
131 type Operation = lro::internal::Operation<
132 crate::model::EnableServiceResponse,
133 crate::model::OperationMetadata,
134 >;
135 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
136 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
137
138 let stub = self.0.stub.clone();
139 let mut options = self.0.options.clone();
140 options.set_retry_policy(gax::retry_policy::NeverRetry);
141 let query = move |name| {
142 let stub = stub.clone();
143 let options = options.clone();
144 async {
145 let op = GetOperation::new(stub)
146 .set_name(name)
147 .with_options(options)
148 .send()
149 .await?;
150 Ok(Operation::new(op))
151 }
152 };
153
154 let start = move || async {
155 let op = self.send().await?;
156 Ok(Operation::new(op))
157 };
158
159 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
160 }
161
162 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
164 self.0.request.name = v.into();
165 self
166 }
167 }
168
169 #[doc(hidden)]
170 impl gax::options::internal::RequestBuilder for EnableService {
171 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
172 &mut self.0.options
173 }
174 }
175
176 #[derive(Clone, Debug)]
194 pub struct DisableService(RequestBuilder<crate::model::DisableServiceRequest>);
195
196 impl DisableService {
197 pub(crate) fn new(
198 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
199 ) -> Self {
200 Self(RequestBuilder::new(stub))
201 }
202
203 pub fn with_request<V: Into<crate::model::DisableServiceRequest>>(mut self, v: V) -> Self {
205 self.0.request = v.into();
206 self
207 }
208
209 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
211 self.0.options = v.into();
212 self
213 }
214
215 pub async fn send(self) -> Result<longrunning::model::Operation> {
222 (*self.0.stub)
223 .disable_service(self.0.request, self.0.options)
224 .await
225 .map(gax::response::Response::into_body)
226 }
227
228 pub fn poller(
230 self,
231 ) -> impl lro::Poller<crate::model::DisableServiceResponse, crate::model::OperationMetadata>
232 {
233 type Operation = lro::internal::Operation<
234 crate::model::DisableServiceResponse,
235 crate::model::OperationMetadata,
236 >;
237 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
238 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
239
240 let stub = self.0.stub.clone();
241 let mut options = self.0.options.clone();
242 options.set_retry_policy(gax::retry_policy::NeverRetry);
243 let query = move |name| {
244 let stub = stub.clone();
245 let options = options.clone();
246 async {
247 let op = GetOperation::new(stub)
248 .set_name(name)
249 .with_options(options)
250 .send()
251 .await?;
252 Ok(Operation::new(op))
253 }
254 };
255
256 let start = move || async {
257 let op = self.send().await?;
258 Ok(Operation::new(op))
259 };
260
261 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
262 }
263
264 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
266 self.0.request.name = v.into();
267 self
268 }
269
270 pub fn set_disable_dependent_services<T: Into<bool>>(mut self, v: T) -> Self {
272 self.0.request.disable_dependent_services = v.into();
273 self
274 }
275
276 pub fn set_check_if_service_has_usage<
278 T: Into<crate::model::disable_service_request::CheckIfServiceHasUsage>,
279 >(
280 mut self,
281 v: T,
282 ) -> Self {
283 self.0.request.check_if_service_has_usage = v.into();
284 self
285 }
286 }
287
288 #[doc(hidden)]
289 impl gax::options::internal::RequestBuilder for DisableService {
290 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
291 &mut self.0.options
292 }
293 }
294
295 #[derive(Clone, Debug)]
312 pub struct GetService(RequestBuilder<crate::model::GetServiceRequest>);
313
314 impl GetService {
315 pub(crate) fn new(
316 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
317 ) -> Self {
318 Self(RequestBuilder::new(stub))
319 }
320
321 pub fn with_request<V: Into<crate::model::GetServiceRequest>>(mut self, v: V) -> Self {
323 self.0.request = v.into();
324 self
325 }
326
327 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
329 self.0.options = v.into();
330 self
331 }
332
333 pub async fn send(self) -> Result<crate::model::Service> {
335 (*self.0.stub)
336 .get_service(self.0.request, self.0.options)
337 .await
338 .map(gax::response::Response::into_body)
339 }
340
341 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
343 self.0.request.name = v.into();
344 self
345 }
346 }
347
348 #[doc(hidden)]
349 impl gax::options::internal::RequestBuilder for GetService {
350 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
351 &mut self.0.options
352 }
353 }
354
355 #[derive(Clone, Debug)]
376 pub struct ListServices(RequestBuilder<crate::model::ListServicesRequest>);
377
378 impl ListServices {
379 pub(crate) fn new(
380 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
381 ) -> Self {
382 Self(RequestBuilder::new(stub))
383 }
384
385 pub fn with_request<V: Into<crate::model::ListServicesRequest>>(mut self, v: V) -> Self {
387 self.0.request = v.into();
388 self
389 }
390
391 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
393 self.0.options = v.into();
394 self
395 }
396
397 pub async fn send(self) -> Result<crate::model::ListServicesResponse> {
399 (*self.0.stub)
400 .list_services(self.0.request, self.0.options)
401 .await
402 .map(gax::response::Response::into_body)
403 }
404
405 pub fn by_page(
407 self,
408 ) -> impl gax::paginator::Paginator<crate::model::ListServicesResponse, gax::error::Error>
409 {
410 use std::clone::Clone;
411 let token = self.0.request.page_token.clone();
412 let execute = move |token: String| {
413 let mut builder = self.clone();
414 builder.0.request = builder.0.request.set_page_token(token);
415 builder.send()
416 };
417 gax::paginator::internal::new_paginator(token, execute)
418 }
419
420 pub fn by_item(
422 self,
423 ) -> impl gax::paginator::ItemPaginator<crate::model::ListServicesResponse, gax::error::Error>
424 {
425 use gax::paginator::Paginator;
426 self.by_page().items()
427 }
428
429 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
431 self.0.request.parent = v.into();
432 self
433 }
434
435 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
437 self.0.request.page_size = v.into();
438 self
439 }
440
441 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
443 self.0.request.page_token = v.into();
444 self
445 }
446
447 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
449 self.0.request.filter = v.into();
450 self
451 }
452 }
453
454 #[doc(hidden)]
455 impl gax::options::internal::RequestBuilder for ListServices {
456 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
457 &mut self.0.options
458 }
459 }
460
461 #[derive(Clone, Debug)]
479 pub struct BatchEnableServices(RequestBuilder<crate::model::BatchEnableServicesRequest>);
480
481 impl BatchEnableServices {
482 pub(crate) fn new(
483 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
484 ) -> Self {
485 Self(RequestBuilder::new(stub))
486 }
487
488 pub fn with_request<V: Into<crate::model::BatchEnableServicesRequest>>(
490 mut self,
491 v: V,
492 ) -> Self {
493 self.0.request = v.into();
494 self
495 }
496
497 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
499 self.0.options = v.into();
500 self
501 }
502
503 pub async fn send(self) -> Result<longrunning::model::Operation> {
510 (*self.0.stub)
511 .batch_enable_services(self.0.request, self.0.options)
512 .await
513 .map(gax::response::Response::into_body)
514 }
515
516 pub fn poller(
518 self,
519 ) -> impl lro::Poller<crate::model::BatchEnableServicesResponse, crate::model::OperationMetadata>
520 {
521 type Operation = lro::internal::Operation<
522 crate::model::BatchEnableServicesResponse,
523 crate::model::OperationMetadata,
524 >;
525 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
526 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
527
528 let stub = self.0.stub.clone();
529 let mut options = self.0.options.clone();
530 options.set_retry_policy(gax::retry_policy::NeverRetry);
531 let query = move |name| {
532 let stub = stub.clone();
533 let options = options.clone();
534 async {
535 let op = GetOperation::new(stub)
536 .set_name(name)
537 .with_options(options)
538 .send()
539 .await?;
540 Ok(Operation::new(op))
541 }
542 };
543
544 let start = move || async {
545 let op = self.send().await?;
546 Ok(Operation::new(op))
547 };
548
549 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
550 }
551
552 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
554 self.0.request.parent = v.into();
555 self
556 }
557
558 pub fn set_service_ids<T, V>(mut self, v: T) -> Self
560 where
561 T: std::iter::IntoIterator<Item = V>,
562 V: std::convert::Into<std::string::String>,
563 {
564 use std::iter::Iterator;
565 self.0.request.service_ids = v.into_iter().map(|i| i.into()).collect();
566 self
567 }
568 }
569
570 #[doc(hidden)]
571 impl gax::options::internal::RequestBuilder for BatchEnableServices {
572 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
573 &mut self.0.options
574 }
575 }
576
577 #[derive(Clone, Debug)]
594 pub struct BatchGetServices(RequestBuilder<crate::model::BatchGetServicesRequest>);
595
596 impl BatchGetServices {
597 pub(crate) fn new(
598 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
599 ) -> Self {
600 Self(RequestBuilder::new(stub))
601 }
602
603 pub fn with_request<V: Into<crate::model::BatchGetServicesRequest>>(
605 mut self,
606 v: V,
607 ) -> Self {
608 self.0.request = v.into();
609 self
610 }
611
612 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
614 self.0.options = v.into();
615 self
616 }
617
618 pub async fn send(self) -> Result<crate::model::BatchGetServicesResponse> {
620 (*self.0.stub)
621 .batch_get_services(self.0.request, self.0.options)
622 .await
623 .map(gax::response::Response::into_body)
624 }
625
626 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
628 self.0.request.parent = v.into();
629 self
630 }
631
632 pub fn set_names<T, V>(mut self, v: T) -> Self
634 where
635 T: std::iter::IntoIterator<Item = V>,
636 V: std::convert::Into<std::string::String>,
637 {
638 use std::iter::Iterator;
639 self.0.request.names = v.into_iter().map(|i| i.into()).collect();
640 self
641 }
642 }
643
644 #[doc(hidden)]
645 impl gax::options::internal::RequestBuilder for BatchGetServices {
646 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
647 &mut self.0.options
648 }
649 }
650
651 #[derive(Clone, Debug)]
672 pub struct ListOperations(RequestBuilder<longrunning::model::ListOperationsRequest>);
673
674 impl ListOperations {
675 pub(crate) fn new(
676 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
677 ) -> Self {
678 Self(RequestBuilder::new(stub))
679 }
680
681 pub fn with_request<V: Into<longrunning::model::ListOperationsRequest>>(
683 mut self,
684 v: V,
685 ) -> Self {
686 self.0.request = v.into();
687 self
688 }
689
690 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
692 self.0.options = v.into();
693 self
694 }
695
696 pub async fn send(self) -> Result<longrunning::model::ListOperationsResponse> {
698 (*self.0.stub)
699 .list_operations(self.0.request, self.0.options)
700 .await
701 .map(gax::response::Response::into_body)
702 }
703
704 pub fn by_page(
706 self,
707 ) -> impl gax::paginator::Paginator<longrunning::model::ListOperationsResponse, gax::error::Error>
708 {
709 use std::clone::Clone;
710 let token = self.0.request.page_token.clone();
711 let execute = move |token: String| {
712 let mut builder = self.clone();
713 builder.0.request = builder.0.request.set_page_token(token);
714 builder.send()
715 };
716 gax::paginator::internal::new_paginator(token, execute)
717 }
718
719 pub fn by_item(
721 self,
722 ) -> impl gax::paginator::ItemPaginator<
723 longrunning::model::ListOperationsResponse,
724 gax::error::Error,
725 > {
726 use gax::paginator::Paginator;
727 self.by_page().items()
728 }
729
730 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
732 self.0.request.name = v.into();
733 self
734 }
735
736 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
738 self.0.request.filter = v.into();
739 self
740 }
741
742 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
744 self.0.request.page_size = v.into();
745 self
746 }
747
748 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
750 self.0.request.page_token = v.into();
751 self
752 }
753
754 pub fn set_return_partial_success<T: Into<bool>>(mut self, v: T) -> Self {
756 self.0.request.return_partial_success = v.into();
757 self
758 }
759 }
760
761 #[doc(hidden)]
762 impl gax::options::internal::RequestBuilder for ListOperations {
763 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
764 &mut self.0.options
765 }
766 }
767
768 #[derive(Clone, Debug)]
785 pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
786
787 impl GetOperation {
788 pub(crate) fn new(
789 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
790 ) -> Self {
791 Self(RequestBuilder::new(stub))
792 }
793
794 pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
796 mut self,
797 v: V,
798 ) -> Self {
799 self.0.request = v.into();
800 self
801 }
802
803 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
805 self.0.options = v.into();
806 self
807 }
808
809 pub async fn send(self) -> Result<longrunning::model::Operation> {
811 (*self.0.stub)
812 .get_operation(self.0.request, self.0.options)
813 .await
814 .map(gax::response::Response::into_body)
815 }
816
817 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
819 self.0.request.name = v.into();
820 self
821 }
822 }
823
824 #[doc(hidden)]
825 impl gax::options::internal::RequestBuilder for GetOperation {
826 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
827 &mut self.0.options
828 }
829 }
830}