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