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 /// Sets the value of [return_partial_success][crate::model::ListOperationsRequest::return_partial_success].
174 pub fn set_return_partial_success<T: Into<bool>>(mut self, v: T) -> Self {
175 self.0.request.return_partial_success = v.into();
176 self
177 }
178 }
179
180 #[doc(hidden)]
181 impl gax::options::internal::RequestBuilder for ListOperations {
182 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
183 &mut self.0.options
184 }
185 }
186
187 /// The request builder for [Operations::get_operation][crate::client::Operations::get_operation] calls.
188 ///
189 /// # Example
190 /// ```no_run
191 /// # use google_cloud_longrunning::builder;
192 /// use builder::operations::GetOperation;
193 /// # tokio_test::block_on(async {
194 ///
195 /// let builder = prepare_request_builder();
196 /// let response = builder.send().await?;
197 /// # gax::Result::<()>::Ok(()) });
198 ///
199 /// fn prepare_request_builder() -> GetOperation {
200 /// # panic!();
201 /// // ... details omitted ...
202 /// }
203 /// ```
204 #[derive(Clone, Debug)]
205 pub struct GetOperation(RequestBuilder<crate::model::GetOperationRequest>);
206
207 impl GetOperation {
208 pub(crate) fn new(
209 stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
210 ) -> Self {
211 Self(RequestBuilder::new(stub))
212 }
213
214 /// Sets the full request, replacing any prior values.
215 pub fn with_request<V: Into<crate::model::GetOperationRequest>>(mut self, v: V) -> Self {
216 self.0.request = v.into();
217 self
218 }
219
220 /// Sets all the options, replacing any prior values.
221 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
222 self.0.options = v.into();
223 self
224 }
225
226 /// Sends the request.
227 pub async fn send(self) -> Result<crate::model::Operation> {
228 (*self.0.stub)
229 .get_operation(self.0.request, self.0.options)
230 .await
231 .map(gax::response::Response::into_body)
232 }
233
234 /// Sets the value of [name][crate::model::GetOperationRequest::name].
235 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
236 self.0.request.name = v.into();
237 self
238 }
239 }
240
241 #[doc(hidden)]
242 impl gax::options::internal::RequestBuilder for GetOperation {
243 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
244 &mut self.0.options
245 }
246 }
247
248 /// The request builder for [Operations::delete_operation][crate::client::Operations::delete_operation] calls.
249 ///
250 /// # Example
251 /// ```no_run
252 /// # use google_cloud_longrunning::builder;
253 /// use builder::operations::DeleteOperation;
254 /// # tokio_test::block_on(async {
255 ///
256 /// let builder = prepare_request_builder();
257 /// let response = builder.send().await?;
258 /// # gax::Result::<()>::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<gax::options::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(gax::response::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 gax::options::internal::RequestBuilder for DeleteOperation {
304 fn request_options(&mut self) -> &mut gax::options::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 /// ```no_run
313 /// # use google_cloud_longrunning::builder;
314 /// use builder::operations::CancelOperation;
315 /// # tokio_test::block_on(async {
316 ///
317 /// let builder = prepare_request_builder();
318 /// let response = builder.send().await?;
319 /// # gax::Result::<()>::Ok(()) });
320 ///
321 /// fn prepare_request_builder() -> CancelOperation {
322 /// # panic!();
323 /// // ... details omitted ...
324 /// }
325 /// ```
326 #[derive(Clone, Debug)]
327 pub struct CancelOperation(RequestBuilder<crate::model::CancelOperationRequest>);
328
329 impl CancelOperation {
330 pub(crate) fn new(
331 stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
332 ) -> Self {
333 Self(RequestBuilder::new(stub))
334 }
335
336 /// Sets the full request, replacing any prior values.
337 pub fn with_request<V: Into<crate::model::CancelOperationRequest>>(mut self, v: V) -> Self {
338 self.0.request = v.into();
339 self
340 }
341
342 /// Sets all the options, replacing any prior values.
343 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
344 self.0.options = v.into();
345 self
346 }
347
348 /// Sends the request.
349 pub async fn send(self) -> Result<()> {
350 (*self.0.stub)
351 .cancel_operation(self.0.request, self.0.options)
352 .await
353 .map(gax::response::Response::into_body)
354 }
355
356 /// Sets the value of [name][crate::model::CancelOperationRequest::name].
357 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
358 self.0.request.name = v.into();
359 self
360 }
361 }
362
363 #[doc(hidden)]
364 impl gax::options::internal::RequestBuilder for CancelOperation {
365 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
366 &mut self.0.options
367 }
368 }
369}