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