google_cloud_optimization_v1/
builder.rs1pub mod fleet_routing {
18 use crate::Result;
19
20 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::FleetRouting;
38 pub struct Factory;
39 impl gax::client_builder::internal::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 ) -> gax::client_builder::Result<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: 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::FleetRouting>,
65 ) -> Self {
66 Self {
67 stub,
68 request: R::default(),
69 options: gax::options::RequestOptions::default(),
70 }
71 }
72 }
73
74 #[derive(Clone, Debug)]
92 pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
93
94 impl OptimizeTours {
95 pub(crate) fn new(
96 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
97 ) -> Self {
98 Self(RequestBuilder::new(stub))
99 }
100
101 pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
103 self.0.request = v.into();
104 self
105 }
106
107 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
109 self.0.options = v.into();
110 self
111 }
112
113 pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
115 (*self.0.stub)
116 .optimize_tours(self.0.request, self.0.options)
117 .await
118 .map(gax::response::Response::into_body)
119 }
120
121 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
125 self.0.request.parent = v.into();
126 self
127 }
128
129 pub fn set_timeout<T>(mut self, v: T) -> Self
131 where
132 T: std::convert::Into<wkt::Duration>,
133 {
134 self.0.request.timeout = std::option::Option::Some(v.into());
135 self
136 }
137
138 pub fn set_or_clear_timeout<T>(mut self, v: std::option::Option<T>) -> Self
140 where
141 T: std::convert::Into<wkt::Duration>,
142 {
143 self.0.request.timeout = v.map(|x| x.into());
144 self
145 }
146
147 pub fn set_model<T>(mut self, v: T) -> Self
149 where
150 T: std::convert::Into<crate::model::ShipmentModel>,
151 {
152 self.0.request.model = std::option::Option::Some(v.into());
153 self
154 }
155
156 pub fn set_or_clear_model<T>(mut self, v: std::option::Option<T>) -> Self
158 where
159 T: std::convert::Into<crate::model::ShipmentModel>,
160 {
161 self.0.request.model = v.map(|x| x.into());
162 self
163 }
164
165 pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
167 mut self,
168 v: T,
169 ) -> Self {
170 self.0.request.solving_mode = v.into();
171 self
172 }
173
174 pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
176 mut self,
177 v: T,
178 ) -> Self {
179 self.0.request.search_mode = v.into();
180 self
181 }
182
183 pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
185 where
186 T: std::iter::IntoIterator<Item = V>,
187 V: std::convert::Into<crate::model::ShipmentRoute>,
188 {
189 use std::iter::Iterator;
190 self.0.request.injected_first_solution_routes =
191 v.into_iter().map(|i| i.into()).collect();
192 self
193 }
194
195 pub fn set_injected_solution_constraint<T>(mut self, v: T) -> Self
197 where
198 T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
199 {
200 self.0.request.injected_solution_constraint = std::option::Option::Some(v.into());
201 self
202 }
203
204 pub fn set_or_clear_injected_solution_constraint<T>(
206 mut self,
207 v: std::option::Option<T>,
208 ) -> Self
209 where
210 T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
211 {
212 self.0.request.injected_solution_constraint = v.map(|x| x.into());
213 self
214 }
215
216 pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
218 where
219 T: std::iter::IntoIterator<Item = V>,
220 V: std::convert::Into<crate::model::ShipmentRoute>,
221 {
222 use std::iter::Iterator;
223 self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
224 self
225 }
226
227 pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
229 mut self,
230 v: T,
231 ) -> Self {
232 self.0.request.interpret_injected_solutions_using_labels = v.into();
233 self
234 }
235
236 pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
238 self.0.request.consider_road_traffic = v.into();
239 self
240 }
241
242 pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
244 self.0.request.populate_polylines = v.into();
245 self
246 }
247
248 pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
250 self.0.request.populate_transition_polylines = v.into();
251 self
252 }
253
254 pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
256 mut self,
257 v: T,
258 ) -> Self {
259 self.0
260 .request
261 .allow_large_deadline_despite_interruption_risk = v.into();
262 self
263 }
264
265 pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
267 self.0.request.use_geodesic_distances = v.into();
268 self
269 }
270
271 pub fn set_geodesic_meters_per_second<T>(mut self, v: T) -> Self
273 where
274 T: std::convert::Into<f64>,
275 {
276 self.0.request.geodesic_meters_per_second = std::option::Option::Some(v.into());
277 self
278 }
279
280 pub fn set_or_clear_geodesic_meters_per_second<T>(
282 mut self,
283 v: std::option::Option<T>,
284 ) -> Self
285 where
286 T: std::convert::Into<f64>,
287 {
288 self.0.request.geodesic_meters_per_second = v.map(|x| x.into());
289 self
290 }
291
292 pub fn set_max_validation_errors<T>(mut self, v: T) -> Self
294 where
295 T: std::convert::Into<i32>,
296 {
297 self.0.request.max_validation_errors = std::option::Option::Some(v.into());
298 self
299 }
300
301 pub fn set_or_clear_max_validation_errors<T>(mut self, v: std::option::Option<T>) -> Self
303 where
304 T: std::convert::Into<i32>,
305 {
306 self.0.request.max_validation_errors = v.map(|x| x.into());
307 self
308 }
309
310 pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
312 self.0.request.label = v.into();
313 self
314 }
315
316 #[deprecated]
318 pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
319 self.0.request.populate_travel_step_polylines = v.into();
320 self
321 }
322 }
323
324 #[doc(hidden)]
325 impl gax::options::internal::RequestBuilder for OptimizeTours {
326 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
327 &mut self.0.options
328 }
329 }
330
331 #[derive(Clone, Debug)]
350 pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
351
352 impl BatchOptimizeTours {
353 pub(crate) fn new(
354 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
355 ) -> Self {
356 Self(RequestBuilder::new(stub))
357 }
358
359 pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
361 mut self,
362 v: V,
363 ) -> Self {
364 self.0.request = v.into();
365 self
366 }
367
368 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
370 self.0.options = v.into();
371 self
372 }
373
374 pub async fn send(self) -> Result<longrunning::model::Operation> {
381 (*self.0.stub)
382 .batch_optimize_tours(self.0.request, self.0.options)
383 .await
384 .map(gax::response::Response::into_body)
385 }
386
387 pub fn poller(
389 self,
390 ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
391 {
392 type Operation = 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(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 lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
421 }
422
423 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
427 self.0.request.parent = v.into();
428 self
429 }
430
431 pub fn set_model_configs<T, V>(mut self, v: T) -> Self
435 where
436 T: std::iter::IntoIterator<Item = V>,
437 V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
438 {
439 use std::iter::Iterator;
440 self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
441 self
442 }
443 }
444
445 #[doc(hidden)]
446 impl gax::options::internal::RequestBuilder for BatchOptimizeTours {
447 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
448 &mut self.0.options
449 }
450 }
451
452 #[derive(Clone, Debug)]
470 pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
471
472 impl GetOperation {
473 pub(crate) fn new(
474 stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
475 ) -> Self {
476 Self(RequestBuilder::new(stub))
477 }
478
479 pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
481 mut self,
482 v: V,
483 ) -> Self {
484 self.0.request = v.into();
485 self
486 }
487
488 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
490 self.0.options = v.into();
491 self
492 }
493
494 pub async fn send(self) -> Result<longrunning::model::Operation> {
496 (*self.0.stub)
497 .get_operation(self.0.request, self.0.options)
498 .await
499 .map(gax::response::Response::into_body)
500 }
501
502 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
504 self.0.request.name = v.into();
505 self
506 }
507 }
508
509 #[doc(hidden)]
510 impl gax::options::internal::RequestBuilder for GetOperation {
511 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
512 &mut self.0.options
513 }
514 }
515}