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
17/// Request and client builders for [Operations][crate::client::Operations].
18pub mod operations {
19 use crate::Result;
20
21 /// A builder for [Operations][crate::client::Operations].
22 ///
23 /// ```
24 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
25 /// # use google_cloud_longrunning::*;
26 /// # use builder::operations::ClientBuilder;
27 /// # use client::Operations;
28 /// let builder : ClientBuilder = Operations::builder();
29 /// let client = builder
30 /// .with_endpoint("https://longrunning.googleapis.com")
31 /// .build().await?;
32 /// # Ok(()) }
33 /// ```
34 pub type ClientBuilder = crate::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 crate::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 ) -> crate::ClientBuilderResult<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: crate::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: crate::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() -> google_cloud_longrunning::Result<()> {
80 /// use google_cloud_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<crate::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(crate::Response::into_body)
122 }
123
124 /// Streams each page in the collection.
125 pub fn by_page(
126 self,
127 ) -> impl google_cloud_gax::paginator::Paginator<
128 crate::model::ListOperationsResponse,
129 crate::Error,
130 > {
131 use std::clone::Clone;
132 let token = self.0.request.page_token.clone();
133 let execute = move |token: String| {
134 let mut builder = self.clone();
135 builder.0.request = builder.0.request.set_page_token(token);
136 builder.send()
137 };
138 google_cloud_gax::paginator::internal::new_paginator(token, execute)
139 }
140
141 /// Streams each item in the collection.
142 pub fn by_item(
143 self,
144 ) -> impl google_cloud_gax::paginator::ItemPaginator<
145 crate::model::ListOperationsResponse,
146 crate::Error,
147 > {
148 use google_cloud_gax::paginator::Paginator;
149 self.by_page().items()
150 }
151
152 /// Sets the value of [name][crate::model::ListOperationsRequest::name].
153 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
154 self.0.request.name = v.into();
155 self
156 }
157
158 /// Sets the value of [filter][crate::model::ListOperationsRequest::filter].
159 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
160 self.0.request.filter = v.into();
161 self
162 }
163
164 /// Sets the value of [page_size][crate::model::ListOperationsRequest::page_size].
165 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
166 self.0.request.page_size = v.into();
167 self
168 }
169
170 /// Sets the value of [page_token][crate::model::ListOperationsRequest::page_token].
171 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
172 self.0.request.page_token = v.into();
173 self
174 }
175
176 /// Sets the value of [return_partial_success][crate::model::ListOperationsRequest::return_partial_success].
177 pub fn set_return_partial_success<T: Into<bool>>(mut self, v: T) -> Self {
178 self.0.request.return_partial_success = v.into();
179 self
180 }
181 }
182
183 #[doc(hidden)]
184 impl crate::RequestBuilder for ListOperations {
185 fn request_options(&mut self) -> &mut crate::RequestOptions {
186 &mut self.0.options
187 }
188 }
189
190 /// The request builder for [Operations::get_operation][crate::client::Operations::get_operation] calls.
191 ///
192 /// # Example
193 /// ```
194 /// # use google_cloud_longrunning::builder::operations::GetOperation;
195 /// # async fn sample() -> google_cloud_longrunning::Result<()> {
196 ///
197 /// let builder = prepare_request_builder();
198 /// let response = builder.send().await?;
199 /// # Ok(()) }
200 ///
201 /// fn prepare_request_builder() -> GetOperation {
202 /// # panic!();
203 /// // ... details omitted ...
204 /// }
205 /// ```
206 #[derive(Clone, Debug)]
207 pub struct GetOperation(RequestBuilder<crate::model::GetOperationRequest>);
208
209 impl GetOperation {
210 pub(crate) fn new(
211 stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
212 ) -> Self {
213 Self(RequestBuilder::new(stub))
214 }
215
216 /// Sets the full request, replacing any prior values.
217 pub fn with_request<V: Into<crate::model::GetOperationRequest>>(mut self, v: V) -> Self {
218 self.0.request = v.into();
219 self
220 }
221
222 /// Sets all the options, replacing any prior values.
223 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
224 self.0.options = v.into();
225 self
226 }
227
228 /// Sends the request.
229 pub async fn send(self) -> Result<crate::model::Operation> {
230 (*self.0.stub)
231 .get_operation(self.0.request, self.0.options)
232 .await
233 .map(crate::Response::into_body)
234 }
235
236 /// Sets the value of [name][crate::model::GetOperationRequest::name].
237 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
238 self.0.request.name = v.into();
239 self
240 }
241 }
242
243 #[doc(hidden)]
244 impl crate::RequestBuilder for GetOperation {
245 fn request_options(&mut self) -> &mut crate::RequestOptions {
246 &mut self.0.options
247 }
248 }
249
250 /// The request builder for [Operations::delete_operation][crate::client::Operations::delete_operation] calls.
251 ///
252 /// # Example
253 /// ```
254 /// # use google_cloud_longrunning::builder::operations::DeleteOperation;
255 /// # async fn sample() -> google_cloud_longrunning::Result<()> {
256 ///
257 /// let builder = prepare_request_builder();
258 /// let response = builder.send().await?;
259 /// # Ok(()) }
260 ///
261 /// fn prepare_request_builder() -> DeleteOperation {
262 /// # panic!();
263 /// // ... details omitted ...
264 /// }
265 /// ```
266 #[derive(Clone, Debug)]
267 pub struct DeleteOperation(RequestBuilder<crate::model::DeleteOperationRequest>);
268
269 impl DeleteOperation {
270 pub(crate) fn new(
271 stub: std::sync::Arc<dyn super::super::stub::dynamic::Operations>,
272 ) -> Self {
273 Self(RequestBuilder::new(stub))
274 }
275
276 /// Sets the full request, replacing any prior values.
277 pub fn with_request<V: Into<crate::model::DeleteOperationRequest>>(mut self, v: V) -> Self {
278 self.0.request = v.into();
279 self
280 }
281
282 /// Sets all the options, replacing any prior values.
283 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
284 self.0.options = v.into();
285 self
286 }
287
288 /// Sends the request.
289 pub async fn send(self) -> Result<()> {
290 (*self.0.stub)
291 .delete_operation(self.0.request, self.0.options)
292 .await
293 .map(crate::Response::into_body)
294 }
295
296 /// Sets the value of [name][crate::model::DeleteOperationRequest::name].
297 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
298 self.0.request.name = v.into();
299 self
300 }
301 }
302
303 #[doc(hidden)]
304 impl crate::RequestBuilder for DeleteOperation {
305 fn request_options(&mut self) -> &mut crate::RequestOptions {
306 &mut self.0.options
307 }
308 }
309
310 /// The request builder for [Operations::cancel_operation][crate::client::Operations::cancel_operation] calls.
311 ///
312 /// # Example
313 /// ```
314 /// # use google_cloud_longrunning::builder::operations::CancelOperation;
315 /// # async fn sample() -> google_cloud_longrunning::Result<()> {
316 ///
317 /// let builder = prepare_request_builder();
318 /// let response = builder.send().await?;
319 /// # 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<crate::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(crate::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 crate::RequestBuilder for CancelOperation {
365 fn request_options(&mut self) -> &mut crate::RequestOptions {
366 &mut self.0.options
367 }
368 }
369}