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