google_cloud_optimization_v1/
builders.rs1pub mod fleet_routing {
18 use crate::Result;
19 use std::sync::Arc;
20
21 #[derive(Clone, Debug)]
23 pub struct RequestBuilder<R: std::default::Default> {
24 stub: Arc<dyn crate::stubs::dynamic::FleetRouting>,
25 request: R,
26 options: gax::options::RequestOptions,
27 }
28
29 impl<R> RequestBuilder<R>
30 where
31 R: std::default::Default,
32 {
33 pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
34 Self {
35 stub,
36 request: R::default(),
37 options: gax::options::RequestOptions::default(),
38 }
39 }
40 }
41
42 #[derive(Clone, Debug)]
44 pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
45
46 impl OptimizeTours {
47 pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
48 Self(RequestBuilder::new(stub))
49 }
50
51 pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
53 self.0.request = v.into();
54 self
55 }
56
57 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
59 self.0.options = v.into();
60 self
61 }
62
63 pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
65 (*self.0.stub)
66 .optimize_tours(self.0.request, self.0.options)
67 .await
68 }
69
70 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
72 self.0.request.parent = v.into();
73 self
74 }
75
76 pub fn set_timeout<T: Into<std::option::Option<wkt::Duration>>>(mut self, v: T) -> Self {
78 self.0.request.timeout = v.into();
79 self
80 }
81
82 pub fn set_model<T: Into<std::option::Option<crate::model::ShipmentModel>>>(
84 mut self,
85 v: T,
86 ) -> Self {
87 self.0.request.model = v.into();
88 self
89 }
90
91 pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
93 mut self,
94 v: T,
95 ) -> Self {
96 self.0.request.solving_mode = v.into();
97 self
98 }
99
100 pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
102 mut self,
103 v: T,
104 ) -> Self {
105 self.0.request.search_mode = v.into();
106 self
107 }
108
109 pub fn set_injected_solution_constraint<
111 T: Into<std::option::Option<crate::model::InjectedSolutionConstraint>>,
112 >(
113 mut self,
114 v: T,
115 ) -> Self {
116 self.0.request.injected_solution_constraint = v.into();
117 self
118 }
119
120 pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
122 mut self,
123 v: T,
124 ) -> Self {
125 self.0.request.interpret_injected_solutions_using_labels = v.into();
126 self
127 }
128
129 pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
131 self.0.request.consider_road_traffic = v.into();
132 self
133 }
134
135 pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
137 self.0.request.populate_polylines = v.into();
138 self
139 }
140
141 pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
143 self.0.request.populate_transition_polylines = v.into();
144 self
145 }
146
147 pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
149 mut self,
150 v: T,
151 ) -> Self {
152 self.0
153 .request
154 .allow_large_deadline_despite_interruption_risk = v.into();
155 self
156 }
157
158 pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
160 self.0.request.use_geodesic_distances = v.into();
161 self
162 }
163
164 pub fn set_geodesic_meters_per_second<T: Into<std::option::Option<f64>>>(
166 mut self,
167 v: T,
168 ) -> Self {
169 self.0.request.geodesic_meters_per_second = v.into();
170 self
171 }
172
173 pub fn set_max_validation_errors<T: Into<std::option::Option<i32>>>(
175 mut self,
176 v: T,
177 ) -> Self {
178 self.0.request.max_validation_errors = v.into();
179 self
180 }
181
182 pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
184 self.0.request.label = v.into();
185 self
186 }
187
188 pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
190 self.0.request.populate_travel_step_polylines = v.into();
191 self
192 }
193
194 pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
196 where
197 T: std::iter::IntoIterator<Item = V>,
198 V: std::convert::Into<crate::model::ShipmentRoute>,
199 {
200 use std::iter::Iterator;
201 self.0.request.injected_first_solution_routes =
202 v.into_iter().map(|i| i.into()).collect();
203 self
204 }
205
206 pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
208 where
209 T: std::iter::IntoIterator<Item = V>,
210 V: std::convert::Into<crate::model::ShipmentRoute>,
211 {
212 use std::iter::Iterator;
213 self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
214 self
215 }
216 }
217
218 impl gax::options::RequestBuilder for OptimizeTours {
219 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
220 &mut self.0.options
221 }
222 }
223
224 #[derive(Clone, Debug)]
226 pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
227
228 impl BatchOptimizeTours {
229 pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
230 Self(RequestBuilder::new(stub))
231 }
232
233 pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
235 mut self,
236 v: V,
237 ) -> Self {
238 self.0.request = v.into();
239 self
240 }
241
242 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
244 self.0.options = v.into();
245 self
246 }
247
248 pub async fn send(self) -> Result<longrunning::model::Operation> {
255 (*self.0.stub)
256 .batch_optimize_tours(self.0.request, self.0.options)
257 .await
258 }
259
260 pub fn poller(
262 self,
263 ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
264 {
265 type Operation = lro::Operation<
266 crate::model::BatchOptimizeToursResponse,
267 crate::model::AsyncModelMetadata,
268 >;
269 let polling_policy = self.0.stub.get_polling_policy(&self.0.options);
270 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
271
272 let stub = self.0.stub.clone();
273 let mut options = self.0.options.clone();
274 options.set_retry_policy(gax::retry_policy::NeverRetry);
275 let query = move |name| {
276 let stub = stub.clone();
277 let options = options.clone();
278 async {
279 let op = GetOperation::new(stub)
280 .set_name(name)
281 .with_options(options)
282 .send()
283 .await?;
284 Ok(Operation::new(op))
285 }
286 };
287
288 let start = move || async {
289 let op = self.send().await?;
290 Ok(Operation::new(op))
291 };
292
293 lro::new_poller(polling_policy, polling_backoff_policy, start, query)
294 }
295
296 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
298 self.0.request.parent = v.into();
299 self
300 }
301
302 pub fn set_model_configs<T, V>(mut self, v: T) -> Self
304 where
305 T: std::iter::IntoIterator<Item = V>,
306 V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
307 {
308 use std::iter::Iterator;
309 self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
310 self
311 }
312 }
313
314 impl gax::options::RequestBuilder for BatchOptimizeTours {
315 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
316 &mut self.0.options
317 }
318 }
319
320 #[derive(Clone, Debug)]
322 pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
323
324 impl GetOperation {
325 pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::FleetRouting>) -> Self {
326 Self(RequestBuilder::new(stub))
327 }
328
329 pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
331 mut self,
332 v: V,
333 ) -> Self {
334 self.0.request = v.into();
335 self
336 }
337
338 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
340 self.0.options = v.into();
341 self
342 }
343
344 pub async fn send(self) -> Result<longrunning::model::Operation> {
346 (*self.0.stub)
347 .get_operation(self.0.request, self.0.options)
348 .await
349 }
350
351 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
353 self.0.request.name = v.into();
354 self
355 }
356 }
357
358 impl gax::options::RequestBuilder for GetOperation {
359 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
360 &mut self.0.options
361 }
362 }
363}