google_cloud_optimization_v1/
builder.rs1pub mod fleet_routing {
19 use crate::Result;
20
21 pub type ClientBuilder = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36 pub(crate) mod client {
37 use super::super::super::client::FleetRouting;
38 pub struct Factory;
39 impl crate::ClientFactory for Factory {
40 type Client = FleetRouting;
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 #[derive(Clone, Debug)]
53 pub(crate) struct RequestBuilder<R: std::default::Default> {
54 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
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::FleetRouting>,
65 ) -> Self {
66 Self {
67 stub,
68 request: R::default(),
69 options: crate::RequestOptions::default(),
70 }
71 }
72 }
73
74 #[derive(Clone, Debug)]
91 pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
92
93 impl OptimizeTours {
94 pub(crate) fn new(
95 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
96 ) -> Self {
97 Self(RequestBuilder::new(stub))
98 }
99
100 pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
102 self.0.request = v.into();
103 self
104 }
105
106 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
108 self.0.options = v.into();
109 self
110 }
111
112 pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
114 (*self.0.stub)
115 .optimize_tours(self.0.request, self.0.options)
116 .await
117 .map(crate::Response::into_body)
118 }
119
120 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
124 self.0.request.parent = v.into();
125 self
126 }
127
128 pub fn set_timeout<T>(mut self, v: T) -> Self
130 where
131 T: std::convert::Into<wkt::Duration>,
132 {
133 self.0.request.timeout = std::option::Option::Some(v.into());
134 self
135 }
136
137 pub fn set_or_clear_timeout<T>(mut self, v: std::option::Option<T>) -> Self
139 where
140 T: std::convert::Into<wkt::Duration>,
141 {
142 self.0.request.timeout = v.map(|x| x.into());
143 self
144 }
145
146 pub fn set_model<T>(mut self, v: T) -> Self
148 where
149 T: std::convert::Into<crate::model::ShipmentModel>,
150 {
151 self.0.request.model = std::option::Option::Some(v.into());
152 self
153 }
154
155 pub fn set_or_clear_model<T>(mut self, v: std::option::Option<T>) -> Self
157 where
158 T: std::convert::Into<crate::model::ShipmentModel>,
159 {
160 self.0.request.model = v.map(|x| x.into());
161 self
162 }
163
164 pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
166 mut self,
167 v: T,
168 ) -> Self {
169 self.0.request.solving_mode = v.into();
170 self
171 }
172
173 pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
175 mut self,
176 v: T,
177 ) -> Self {
178 self.0.request.search_mode = v.into();
179 self
180 }
181
182 pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
184 where
185 T: std::iter::IntoIterator<Item = V>,
186 V: std::convert::Into<crate::model::ShipmentRoute>,
187 {
188 use std::iter::Iterator;
189 self.0.request.injected_first_solution_routes =
190 v.into_iter().map(|i| i.into()).collect();
191 self
192 }
193
194 pub fn set_injected_solution_constraint<T>(mut self, v: T) -> Self
196 where
197 T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
198 {
199 self.0.request.injected_solution_constraint = std::option::Option::Some(v.into());
200 self
201 }
202
203 pub fn set_or_clear_injected_solution_constraint<T>(
205 mut self,
206 v: std::option::Option<T>,
207 ) -> Self
208 where
209 T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
210 {
211 self.0.request.injected_solution_constraint = v.map(|x| x.into());
212 self
213 }
214
215 pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
217 where
218 T: std::iter::IntoIterator<Item = V>,
219 V: std::convert::Into<crate::model::ShipmentRoute>,
220 {
221 use std::iter::Iterator;
222 self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
223 self
224 }
225
226 pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
228 mut self,
229 v: T,
230 ) -> Self {
231 self.0.request.interpret_injected_solutions_using_labels = v.into();
232 self
233 }
234
235 pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
237 self.0.request.consider_road_traffic = v.into();
238 self
239 }
240
241 pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
243 self.0.request.populate_polylines = v.into();
244 self
245 }
246
247 pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
249 self.0.request.populate_transition_polylines = v.into();
250 self
251 }
252
253 pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
255 mut self,
256 v: T,
257 ) -> Self {
258 self.0
259 .request
260 .allow_large_deadline_despite_interruption_risk = v.into();
261 self
262 }
263
264 pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
266 self.0.request.use_geodesic_distances = v.into();
267 self
268 }
269
270 pub fn set_geodesic_meters_per_second<T>(mut self, v: T) -> Self
272 where
273 T: std::convert::Into<f64>,
274 {
275 self.0.request.geodesic_meters_per_second = std::option::Option::Some(v.into());
276 self
277 }
278
279 pub fn set_or_clear_geodesic_meters_per_second<T>(
281 mut self,
282 v: std::option::Option<T>,
283 ) -> Self
284 where
285 T: std::convert::Into<f64>,
286 {
287 self.0.request.geodesic_meters_per_second = v.map(|x| x.into());
288 self
289 }
290
291 pub fn set_max_validation_errors<T>(mut self, v: T) -> Self
293 where
294 T: std::convert::Into<i32>,
295 {
296 self.0.request.max_validation_errors = std::option::Option::Some(v.into());
297 self
298 }
299
300 pub fn set_or_clear_max_validation_errors<T>(mut self, v: std::option::Option<T>) -> Self
302 where
303 T: std::convert::Into<i32>,
304 {
305 self.0.request.max_validation_errors = v.map(|x| x.into());
306 self
307 }
308
309 pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
311 self.0.request.label = v.into();
312 self
313 }
314
315 #[deprecated]
317 pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
318 self.0.request.populate_travel_step_polylines = v.into();
319 self
320 }
321 }
322
323 #[doc(hidden)]
324 impl crate::RequestBuilder for OptimizeTours {
325 fn request_options(&mut self) -> &mut crate::RequestOptions {
326 &mut self.0.options
327 }
328 }
329
330 #[derive(Clone, Debug)]
348 pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
349
350 impl BatchOptimizeTours {
351 pub(crate) fn new(
352 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
353 ) -> Self {
354 Self(RequestBuilder::new(stub))
355 }
356
357 pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
359 mut self,
360 v: V,
361 ) -> Self {
362 self.0.request = v.into();
363 self
364 }
365
366 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
368 self.0.options = v.into();
369 self
370 }
371
372 pub async fn send(self) -> Result<google_cloud_longrunning::model::Operation> {
379 (*self.0.stub)
380 .batch_optimize_tours(self.0.request, self.0.options)
381 .await
382 .map(crate::Response::into_body)
383 }
384
385 pub fn poller(
387 self,
388 ) -> impl google_cloud_lro::Poller<
389 crate::model::BatchOptimizeToursResponse,
390 crate::model::AsyncModelMetadata,
391 > {
392 type Operation = google_cloud_lro::internal::Operation<
393 crate::model::BatchOptimizeToursResponse,
394 crate::model::AsyncModelMetadata,
395 >;
396 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
397 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
398
399 let stub = self.0.stub.clone();
400 let mut options = self.0.options.clone();
401 options.set_retry_policy(google_cloud_gax::retry_policy::NeverRetry);
402 let query = move |name| {
403 let stub = stub.clone();
404 let options = options.clone();
405 async {
406 let op = GetOperation::new(stub)
407 .set_name(name)
408 .with_options(options)
409 .send()
410 .await?;
411 Ok(Operation::new(op))
412 }
413 };
414
415 let start = move || async {
416 let op = self.send().await?;
417 Ok(Operation::new(op))
418 };
419
420 google_cloud_lro::internal::new_poller(
421 polling_error_policy,
422 polling_backoff_policy,
423 start,
424 query,
425 )
426 }
427
428 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
432 self.0.request.parent = v.into();
433 self
434 }
435
436 pub fn set_model_configs<T, V>(mut self, v: T) -> Self
440 where
441 T: std::iter::IntoIterator<Item = V>,
442 V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
443 {
444 use std::iter::Iterator;
445 self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
446 self
447 }
448 }
449
450 #[doc(hidden)]
451 impl crate::RequestBuilder for BatchOptimizeTours {
452 fn request_options(&mut self) -> &mut crate::RequestOptions {
453 &mut self.0.options
454 }
455 }
456
457 #[derive(Clone, Debug)]
474 pub struct GetOperation(RequestBuilder<google_cloud_longrunning::model::GetOperationRequest>);
475
476 impl GetOperation {
477 pub(crate) fn new(
478 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
479 ) -> Self {
480 Self(RequestBuilder::new(stub))
481 }
482
483 pub fn with_request<V: Into<google_cloud_longrunning::model::GetOperationRequest>>(
485 mut self,
486 v: V,
487 ) -> Self {
488 self.0.request = v.into();
489 self
490 }
491
492 pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
494 self.0.options = v.into();
495 self
496 }
497
498 pub async fn send(self) -> Result<google_cloud_longrunning::model::Operation> {
500 (*self.0.stub)
501 .get_operation(self.0.request, self.0.options)
502 .await
503 .map(crate::Response::into_body)
504 }
505
506 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
508 self.0.request.name = v.into();
509 self
510 }
511 }
512
513 #[doc(hidden)]
514 impl crate::RequestBuilder for GetOperation {
515 fn request_options(&mut self) -> &mut crate::RequestOptions {
516 &mut self.0.options
517 }
518 }
519}