Skip to main content

google_cloud_longrunning/
builder.rs

1// Copyright 2024 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
17pub mod operations {
18    use crate::Result;
19
20    /// A builder for [Operations][crate::client::Operations].
21    ///
22    /// ```
23    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
24    /// # use google_cloud_longrunning::*;
25    /// # use builder::operations::ClientBuilder;
26    /// # use client::Operations;
27    /// let builder : ClientBuilder = Operations::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://longrunning.googleapis.com")
30    ///     .build().await?;
31    /// # Ok(()) }
32    /// ```
33    pub type ClientBuilder = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;
34
35    pub(crate) mod client {
36        use super::super::super::client::Operations;
37        pub struct Factory;
38        impl crate::ClientFactory for Factory {
39            type Client = Operations;
40            type Credentials = gaxi::options::Credentials;
41            async fn build(
42                self,
43                config: gaxi::options::ClientConfig,
44            ) -> crate::ClientBuilderResult<Self::Client> {
45                Self::Client::new(config).await
46            }
47        }
48    }
49
50    /// Common implementation for [crate::client::Operations] request builders.
51    #[derive(Clone, Debug)]
52    pub(crate) struct RequestBuilder<R: std::default::Default> {
53        stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
54        request: R,
55        options: crate::RequestOptions,
56    }
57
58    impl<R> RequestBuilder<R>
59    where
60        R: std::default::Default,
61    {
62        pub(crate) fn new(
63            stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
64        ) -> Self {
65            Self {
66                stub,
67                request: R::default(),
68                options: crate::RequestOptions::default(),
69            }
70        }
71    }
72
73    /// The request builder for [Operations::list_operations][crate::client::Operations::list_operations] calls.
74    ///
75    /// # Example
76    /// ```
77    /// # use google_cloud_longrunning::builder::operations::ListOperations;
78    /// # async fn sample() -> google_cloud_longrunning::Result<()> {
79    /// use google_cloud_gax::paginator::ItemPaginator;
80    ///
81    /// let builder = prepare_request_builder();
82    /// let mut items = builder.by_item();
83    /// while let Some(result) = items.next().await {
84    ///   let item = result?;
85    /// }
86    /// # Ok(()) }
87    ///
88    /// fn prepare_request_builder() -> ListOperations {
89    ///   # panic!();
90    ///   // ... details omitted ...
91    /// }
92    /// ```
93    #[derive(Clone, Debug)]
94    pub struct ListOperations(RequestBuilder<crate::model::ListOperationsRequest>);
95
96    impl ListOperations {
97        pub(crate) fn new(
98            stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
99        ) -> Self {
100            Self(RequestBuilder::new(stub))
101        }
102
103        /// Sets the full request, replacing any prior values.
104        pub fn with_request<V: Into<crate::model::ListOperationsRequest>>(mut self, v: V) -> Self {
105            self.0.request = v.into();
106            self
107        }
108
109        /// Sets all the options, replacing any prior values.
110        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
111            self.0.options = v.into();
112            self
113        }
114
115        /// Sends the request.
116        pub async fn send(self) -> Result<crate::model::ListOperationsResponse> {
117            (*self.0.stub)
118                .list_operations(self.0.request, self.0.options)
119                .await
120                .map(crate::Response::into_body)
121        }
122
123        /// Streams each page in the collection.
124        pub fn by_page(
125            self,
126        ) -> impl google_cloud_gax::paginator::Paginator<
127            crate::model::ListOperationsResponse,
128            crate::Error,
129        > {
130            use std::clone::Clone;
131            let token = self.0.request.page_token.clone();
132            let execute = move |token: String| {
133                let mut builder = self.clone();
134                builder.0.request = builder.0.request.set_page_token(token);
135                builder.send()
136            };
137            google_cloud_gax::paginator::internal::new_paginator(token, execute)
138        }
139
140        /// Streams each item in the collection.
141        pub fn by_item(
142            self,
143        ) -> impl google_cloud_gax::paginator::ItemPaginator<
144            crate::model::ListOperationsResponse,
145            crate::Error,
146        > {
147            use google_cloud_gax::paginator::Paginator;
148            self.by_page().items()
149        }
150
151        /// Sets the value of [name][crate::model::ListOperationsRequest::name].
152        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
153            self.0.request.name = v.into();
154            self
155        }
156
157        /// Sets the value of [filter][crate::model::ListOperationsRequest::filter].
158        pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
159            self.0.request.filter = v.into();
160            self
161        }
162
163        /// Sets the value of [page_size][crate::model::ListOperationsRequest::page_size].
164        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
165            self.0.request.page_size = v.into();
166            self
167        }
168
169        /// Sets the value of [page_token][crate::model::ListOperationsRequest::page_token].
170        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
171            self.0.request.page_token = v.into();
172            self
173        }
174
175        /// Sets the value of [return_partial_success][crate::model::ListOperationsRequest::return_partial_success].
176        pub fn set_return_partial_success<T: Into<bool>>(mut self, v: T) -> Self {
177            self.0.request.return_partial_success = v.into();
178            self
179        }
180    }
181
182    #[doc(hidden)]
183    impl crate::RequestBuilder for ListOperations {
184        fn request_options(&mut self) -> &mut crate::RequestOptions {
185            &mut self.0.options
186        }
187    }
188
189    /// The request builder for [Operations::get_operation][crate::client::Operations::get_operation] calls.
190    ///
191    /// # Example
192    /// ```
193    /// # use google_cloud_longrunning::builder::operations::GetOperation;
194    /// # async fn sample() -> google_cloud_longrunning::Result<()> {
195    ///
196    /// let builder = prepare_request_builder();
197    /// let response = builder.send().await?;
198    /// # Ok(()) }
199    ///
200    /// fn prepare_request_builder() -> GetOperation {
201    ///   # panic!();
202    ///   // ... details omitted ...
203    /// }
204    /// ```
205    #[derive(Clone, Debug)]
206    pub struct GetOperation(RequestBuilder<crate::model::GetOperationRequest>);
207
208    impl GetOperation {
209        pub(crate) fn new(
210            stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
211        ) -> Self {
212            Self(RequestBuilder::new(stub))
213        }
214
215        /// Sets the full request, replacing any prior values.
216        pub fn with_request<V: Into<crate::model::GetOperationRequest>>(mut self, v: V) -> Self {
217            self.0.request = v.into();
218            self
219        }
220
221        /// Sets all the options, replacing any prior values.
222        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
223            self.0.options = v.into();
224            self
225        }
226
227        /// Sends the request.
228        pub async fn send(self) -> Result<crate::model::Operation> {
229            (*self.0.stub)
230                .get_operation(self.0.request, self.0.options)
231                .await
232                .map(crate::Response::into_body)
233        }
234
235        /// Sets the value of [name][crate::model::GetOperationRequest::name].
236        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
237            self.0.request.name = v.into();
238            self
239        }
240    }
241
242    #[doc(hidden)]
243    impl crate::RequestBuilder for GetOperation {
244        fn request_options(&mut self) -> &mut crate::RequestOptions {
245            &mut self.0.options
246        }
247    }
248
249    /// The request builder for [Operations::delete_operation][crate::client::Operations::delete_operation] calls.
250    ///
251    /// # Example
252    /// ```
253    /// # use google_cloud_longrunning::builder::operations::DeleteOperation;
254    /// # async fn sample() -> google_cloud_longrunning::Result<()> {
255    ///
256    /// let builder = prepare_request_builder();
257    /// let response = builder.send().await?;
258    /// # Ok(()) }
259    ///
260    /// fn prepare_request_builder() -> DeleteOperation {
261    ///   # panic!();
262    ///   // ... details omitted ...
263    /// }
264    /// ```
265    #[derive(Clone, Debug)]
266    pub struct DeleteOperation(RequestBuilder<crate::model::DeleteOperationRequest>);
267
268    impl DeleteOperation {
269        pub(crate) fn new(
270            stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
271        ) -> Self {
272            Self(RequestBuilder::new(stub))
273        }
274
275        /// Sets the full request, replacing any prior values.
276        pub fn with_request<V: Into<crate::model::DeleteOperationRequest>>(mut self, v: V) -> Self {
277            self.0.request = v.into();
278            self
279        }
280
281        /// Sets all the options, replacing any prior values.
282        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
283            self.0.options = v.into();
284            self
285        }
286
287        /// Sends the request.
288        pub async fn send(self) -> Result<()> {
289            (*self.0.stub)
290                .delete_operation(self.0.request, self.0.options)
291                .await
292                .map(crate::Response::into_body)
293        }
294
295        /// Sets the value of [name][crate::model::DeleteOperationRequest::name].
296        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
297            self.0.request.name = v.into();
298            self
299        }
300    }
301
302    #[doc(hidden)]
303    impl crate::RequestBuilder for DeleteOperation {
304        fn request_options(&mut self) -> &mut crate::RequestOptions {
305            &mut self.0.options
306        }
307    }
308
309    /// The request builder for [Operations::cancel_operation][crate::client::Operations::cancel_operation] calls.
310    ///
311    /// # Example
312    /// ```
313    /// # use google_cloud_longrunning::builder::operations::CancelOperation;
314    /// # async fn sample() -> google_cloud_longrunning::Result<()> {
315    ///
316    /// let builder = prepare_request_builder();
317    /// let response = builder.send().await?;
318    /// # Ok(()) }
319    ///
320    /// fn prepare_request_builder() -> CancelOperation {
321    ///   # panic!();
322    ///   // ... details omitted ...
323    /// }
324    /// ```
325    #[derive(Clone, Debug)]
326    pub struct CancelOperation(RequestBuilder<crate::model::CancelOperationRequest>);
327
328    impl CancelOperation {
329        pub(crate) fn new(
330            stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
331        ) -> Self {
332            Self(RequestBuilder::new(stub))
333        }
334
335        /// Sets the full request, replacing any prior values.
336        pub fn with_request<V: Into<crate::model::CancelOperationRequest>>(mut self, v: V) -> Self {
337            self.0.request = v.into();
338            self
339        }
340
341        /// Sets all the options, replacing any prior values.
342        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
343            self.0.options = v.into();
344            self
345        }
346
347        /// Sends the request.
348        pub async fn send(self) -> Result<()> {
349            (*self.0.stub)
350                .cancel_operation(self.0.request, self.0.options)
351                .await
352                .map(crate::Response::into_body)
353        }
354
355        /// Sets the value of [name][crate::model::CancelOperationRequest::name].
356        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
357            self.0.request.name = v.into();
358            self
359        }
360    }
361
362    #[doc(hidden)]
363    impl crate::RequestBuilder for CancelOperation {
364        fn request_options(&mut self) -> &mut crate::RequestOptions {
365            &mut self.0.options
366        }
367    }
368}