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)]
93 pub struct EnableService(RequestBuilder<crate::model::EnableServiceRequest>);
94
95 impl EnableService {
96 pub(crate) fn new(
97 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
98 ) -> Self {
99 Self(RequestBuilder::new(stub))
100 }
101
102 pub fn with_request<V: Into<crate::model::EnableServiceRequest>>(mut self, v: V) -> Self {
104 self.0.request = v.into();
105 self
106 }
107
108 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
110 self.0.options = v.into();
111 self
112 }
113
114 pub async fn send(self) -> Result<longrunning::model::Operation> {
121 (*self.0.stub)
122 .enable_service(self.0.request, self.0.options)
123 .await
124 .map(gax::response::Response::into_body)
125 }
126
127 pub fn poller(
129 self,
130 ) -> impl lro::Poller<crate::model::EnableServiceResponse, crate::model::OperationMetadata>
131 {
132 type Operation = lro::internal::Operation<
133 crate::model::EnableServiceResponse,
134 crate::model::OperationMetadata,
135 >;
136 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
137 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
138
139 let stub = self.0.stub.clone();
140 let mut options = self.0.options.clone();
141 options.set_retry_policy(gax::retry_policy::NeverRetry);
142 let query = move |name| {
143 let stub = stub.clone();
144 let options = options.clone();
145 async {
146 let op = GetOperation::new(stub)
147 .set_name(name)
148 .with_options(options)
149 .send()
150 .await?;
151 Ok(Operation::new(op))
152 }
153 };
154
155 let start = move || async {
156 let op = self.send().await?;
157 Ok(Operation::new(op))
158 };
159
160 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
161 }
162
163 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
165 self.0.request.name = v.into();
166 self
167 }
168 }
169
170 #[doc(hidden)]
171 impl gax::options::internal::RequestBuilder for EnableService {
172 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
173 &mut self.0.options
174 }
175 }
176
177 #[derive(Clone, Debug)]
196 pub struct DisableService(RequestBuilder<crate::model::DisableServiceRequest>);
197
198 impl DisableService {
199 pub(crate) fn new(
200 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
201 ) -> Self {
202 Self(RequestBuilder::new(stub))
203 }
204
205 pub fn with_request<V: Into<crate::model::DisableServiceRequest>>(mut self, v: V) -> Self {
207 self.0.request = v.into();
208 self
209 }
210
211 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
213 self.0.options = v.into();
214 self
215 }
216
217 pub async fn send(self) -> Result<longrunning::model::Operation> {
224 (*self.0.stub)
225 .disable_service(self.0.request, self.0.options)
226 .await
227 .map(gax::response::Response::into_body)
228 }
229
230 pub fn poller(
232 self,
233 ) -> impl lro::Poller<crate::model::DisableServiceResponse, crate::model::OperationMetadata>
234 {
235 type Operation = lro::internal::Operation<
236 crate::model::DisableServiceResponse,
237 crate::model::OperationMetadata,
238 >;
239 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
240 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
241
242 let stub = self.0.stub.clone();
243 let mut options = self.0.options.clone();
244 options.set_retry_policy(gax::retry_policy::NeverRetry);
245 let query = move |name| {
246 let stub = stub.clone();
247 let options = options.clone();
248 async {
249 let op = GetOperation::new(stub)
250 .set_name(name)
251 .with_options(options)
252 .send()
253 .await?;
254 Ok(Operation::new(op))
255 }
256 };
257
258 let start = move || async {
259 let op = self.send().await?;
260 Ok(Operation::new(op))
261 };
262
263 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
264 }
265
266 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
268 self.0.request.name = v.into();
269 self
270 }
271
272 pub fn set_disable_dependent_services<T: Into<bool>>(mut self, v: T) -> Self {
274 self.0.request.disable_dependent_services = v.into();
275 self
276 }
277
278 pub fn set_check_if_service_has_usage<
280 T: Into<crate::model::disable_service_request::CheckIfServiceHasUsage>,
281 >(
282 mut self,
283 v: T,
284 ) -> Self {
285 self.0.request.check_if_service_has_usage = v.into();
286 self
287 }
288 }
289
290 #[doc(hidden)]
291 impl gax::options::internal::RequestBuilder for DisableService {
292 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
293 &mut self.0.options
294 }
295 }
296
297 #[derive(Clone, Debug)]
315 pub struct GetService(RequestBuilder<crate::model::GetServiceRequest>);
316
317 impl GetService {
318 pub(crate) fn new(
319 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
320 ) -> Self {
321 Self(RequestBuilder::new(stub))
322 }
323
324 pub fn with_request<V: Into<crate::model::GetServiceRequest>>(mut self, v: V) -> Self {
326 self.0.request = v.into();
327 self
328 }
329
330 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
332 self.0.options = v.into();
333 self
334 }
335
336 pub async fn send(self) -> Result<crate::model::Service> {
338 (*self.0.stub)
339 .get_service(self.0.request, self.0.options)
340 .await
341 .map(gax::response::Response::into_body)
342 }
343
344 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
346 self.0.request.name = v.into();
347 self
348 }
349 }
350
351 #[doc(hidden)]
352 impl gax::options::internal::RequestBuilder for GetService {
353 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
354 &mut self.0.options
355 }
356 }
357
358 #[derive(Clone, Debug)]
380 pub struct ListServices(RequestBuilder<crate::model::ListServicesRequest>);
381
382 impl ListServices {
383 pub(crate) fn new(
384 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
385 ) -> Self {
386 Self(RequestBuilder::new(stub))
387 }
388
389 pub fn with_request<V: Into<crate::model::ListServicesRequest>>(mut self, v: V) -> Self {
391 self.0.request = v.into();
392 self
393 }
394
395 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
397 self.0.options = v.into();
398 self
399 }
400
401 pub async fn send(self) -> Result<crate::model::ListServicesResponse> {
403 (*self.0.stub)
404 .list_services(self.0.request, self.0.options)
405 .await
406 .map(gax::response::Response::into_body)
407 }
408
409 pub fn by_page(
411 self,
412 ) -> impl gax::paginator::Paginator<crate::model::ListServicesResponse, gax::error::Error>
413 {
414 use std::clone::Clone;
415 let token = self.0.request.page_token.clone();
416 let execute = move |token: String| {
417 let mut builder = self.clone();
418 builder.0.request = builder.0.request.set_page_token(token);
419 builder.send()
420 };
421 gax::paginator::internal::new_paginator(token, execute)
422 }
423
424 pub fn by_item(
426 self,
427 ) -> impl gax::paginator::ItemPaginator<crate::model::ListServicesResponse, gax::error::Error>
428 {
429 use gax::paginator::Paginator;
430 self.by_page().items()
431 }
432
433 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
435 self.0.request.parent = v.into();
436 self
437 }
438
439 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
441 self.0.request.page_size = v.into();
442 self
443 }
444
445 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
447 self.0.request.page_token = v.into();
448 self
449 }
450
451 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
453 self.0.request.filter = v.into();
454 self
455 }
456 }
457
458 #[doc(hidden)]
459 impl gax::options::internal::RequestBuilder for ListServices {
460 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
461 &mut self.0.options
462 }
463 }
464
465 #[derive(Clone, Debug)]
484 pub struct BatchEnableServices(RequestBuilder<crate::model::BatchEnableServicesRequest>);
485
486 impl BatchEnableServices {
487 pub(crate) fn new(
488 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
489 ) -> Self {
490 Self(RequestBuilder::new(stub))
491 }
492
493 pub fn with_request<V: Into<crate::model::BatchEnableServicesRequest>>(
495 mut self,
496 v: V,
497 ) -> Self {
498 self.0.request = v.into();
499 self
500 }
501
502 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
504 self.0.options = v.into();
505 self
506 }
507
508 pub async fn send(self) -> Result<longrunning::model::Operation> {
515 (*self.0.stub)
516 .batch_enable_services(self.0.request, self.0.options)
517 .await
518 .map(gax::response::Response::into_body)
519 }
520
521 pub fn poller(
523 self,
524 ) -> impl lro::Poller<crate::model::BatchEnableServicesResponse, crate::model::OperationMetadata>
525 {
526 type Operation = lro::internal::Operation<
527 crate::model::BatchEnableServicesResponse,
528 crate::model::OperationMetadata,
529 >;
530 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
531 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
532
533 let stub = self.0.stub.clone();
534 let mut options = self.0.options.clone();
535 options.set_retry_policy(gax::retry_policy::NeverRetry);
536 let query = move |name| {
537 let stub = stub.clone();
538 let options = options.clone();
539 async {
540 let op = GetOperation::new(stub)
541 .set_name(name)
542 .with_options(options)
543 .send()
544 .await?;
545 Ok(Operation::new(op))
546 }
547 };
548
549 let start = move || async {
550 let op = self.send().await?;
551 Ok(Operation::new(op))
552 };
553
554 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
555 }
556
557 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
559 self.0.request.parent = v.into();
560 self
561 }
562
563 pub fn set_service_ids<T, V>(mut self, v: T) -> Self
565 where
566 T: std::iter::IntoIterator<Item = V>,
567 V: std::convert::Into<std::string::String>,
568 {
569 use std::iter::Iterator;
570 self.0.request.service_ids = v.into_iter().map(|i| i.into()).collect();
571 self
572 }
573 }
574
575 #[doc(hidden)]
576 impl gax::options::internal::RequestBuilder for BatchEnableServices {
577 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
578 &mut self.0.options
579 }
580 }
581
582 #[derive(Clone, Debug)]
600 pub struct BatchGetServices(RequestBuilder<crate::model::BatchGetServicesRequest>);
601
602 impl BatchGetServices {
603 pub(crate) fn new(
604 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
605 ) -> Self {
606 Self(RequestBuilder::new(stub))
607 }
608
609 pub fn with_request<V: Into<crate::model::BatchGetServicesRequest>>(
611 mut self,
612 v: V,
613 ) -> Self {
614 self.0.request = v.into();
615 self
616 }
617
618 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
620 self.0.options = v.into();
621 self
622 }
623
624 pub async fn send(self) -> Result<crate::model::BatchGetServicesResponse> {
626 (*self.0.stub)
627 .batch_get_services(self.0.request, self.0.options)
628 .await
629 .map(gax::response::Response::into_body)
630 }
631
632 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
634 self.0.request.parent = v.into();
635 self
636 }
637
638 pub fn set_names<T, V>(mut self, v: T) -> Self
640 where
641 T: std::iter::IntoIterator<Item = V>,
642 V: std::convert::Into<std::string::String>,
643 {
644 use std::iter::Iterator;
645 self.0.request.names = v.into_iter().map(|i| i.into()).collect();
646 self
647 }
648 }
649
650 #[doc(hidden)]
651 impl gax::options::internal::RequestBuilder for BatchGetServices {
652 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
653 &mut self.0.options
654 }
655 }
656
657 #[derive(Clone, Debug)]
679 pub struct ListOperations(RequestBuilder<longrunning::model::ListOperationsRequest>);
680
681 impl ListOperations {
682 pub(crate) fn new(
683 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
684 ) -> Self {
685 Self(RequestBuilder::new(stub))
686 }
687
688 pub fn with_request<V: Into<longrunning::model::ListOperationsRequest>>(
690 mut self,
691 v: V,
692 ) -> Self {
693 self.0.request = v.into();
694 self
695 }
696
697 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
699 self.0.options = v.into();
700 self
701 }
702
703 pub async fn send(self) -> Result<longrunning::model::ListOperationsResponse> {
705 (*self.0.stub)
706 .list_operations(self.0.request, self.0.options)
707 .await
708 .map(gax::response::Response::into_body)
709 }
710
711 pub fn by_page(
713 self,
714 ) -> impl gax::paginator::Paginator<longrunning::model::ListOperationsResponse, gax::error::Error>
715 {
716 use std::clone::Clone;
717 let token = self.0.request.page_token.clone();
718 let execute = move |token: String| {
719 let mut builder = self.clone();
720 builder.0.request = builder.0.request.set_page_token(token);
721 builder.send()
722 };
723 gax::paginator::internal::new_paginator(token, execute)
724 }
725
726 pub fn by_item(
728 self,
729 ) -> impl gax::paginator::ItemPaginator<
730 longrunning::model::ListOperationsResponse,
731 gax::error::Error,
732 > {
733 use gax::paginator::Paginator;
734 self.by_page().items()
735 }
736
737 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
739 self.0.request.name = v.into();
740 self
741 }
742
743 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
745 self.0.request.filter = v.into();
746 self
747 }
748
749 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
751 self.0.request.page_size = v.into();
752 self
753 }
754
755 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
757 self.0.request.page_token = v.into();
758 self
759 }
760 }
761
762 #[doc(hidden)]
763 impl gax::options::internal::RequestBuilder for ListOperations {
764 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
765 &mut self.0.options
766 }
767 }
768
769 #[derive(Clone, Debug)]
787 pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
788
789 impl GetOperation {
790 pub(crate) fn new(
791 stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceUsage>,
792 ) -> Self {
793 Self(RequestBuilder::new(stub))
794 }
795
796 pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
798 mut self,
799 v: V,
800 ) -> Self {
801 self.0.request = v.into();
802 self
803 }
804
805 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
807 self.0.options = v.into();
808 self
809 }
810
811 pub async fn send(self) -> Result<longrunning::model::Operation> {
813 (*self.0.stub)
814 .get_operation(self.0.request, self.0.options)
815 .await
816 .map(gax::response::Response::into_body)
817 }
818
819 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
821 self.0.request.name = v.into();
822 self
823 }
824 }
825
826 #[doc(hidden)]
827 impl gax::options::internal::RequestBuilder for GetOperation {
828 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
829 &mut self.0.options
830 }
831 }
832}