google_cloud_optimization_v1/
builder.rs1pub mod fleet_routing {
18 use crate::Result;
19 use std::sync::Arc;
20
21 pub type ClientBuilder =
35 gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
36
37 pub(crate) mod client {
38 use super::super::super::client::FleetRouting;
39 pub struct Factory;
40 impl gax::client_builder::internal::ClientFactory for Factory {
41 type Client = FleetRouting;
42 type Credentials = gaxi::options::Credentials;
43 async fn build(self, config: gaxi::options::ClientConfig) -> gax::Result<Self::Client> {
44 Self::Client::new(config).await
45 }
46 }
47 }
48
49 #[derive(Clone, Debug)]
51 pub(crate) struct RequestBuilder<R: std::default::Default> {
52 stub: Arc<dyn super::super::stub::dynamic::FleetRouting>,
53 request: R,
54 options: gax::options::RequestOptions,
55 }
56
57 impl<R> RequestBuilder<R>
58 where
59 R: std::default::Default,
60 {
61 pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::FleetRouting>) -> Self {
62 Self {
63 stub,
64 request: R::default(),
65 options: gax::options::RequestOptions::default(),
66 }
67 }
68 }
69
70 #[derive(Clone, Debug)]
72 pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);
73
74 impl OptimizeTours {
75 pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::FleetRouting>) -> Self {
76 Self(RequestBuilder::new(stub))
77 }
78
79 pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
81 self.0.request = v.into();
82 self
83 }
84
85 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
87 self.0.options = v.into();
88 self
89 }
90
91 pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
93 (*self.0.stub)
94 .optimize_tours(self.0.request, self.0.options)
95 .await
96 .map(gax::response::Response::into_body)
97 }
98
99 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
101 self.0.request.parent = v.into();
102 self
103 }
104
105 pub fn set_timeout<T: Into<std::option::Option<wkt::Duration>>>(mut self, v: T) -> Self {
107 self.0.request.timeout = v.into();
108 self
109 }
110
111 pub fn set_model<T: Into<std::option::Option<crate::model::ShipmentModel>>>(
113 mut self,
114 v: T,
115 ) -> Self {
116 self.0.request.model = v.into();
117 self
118 }
119
120 pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
122 mut self,
123 v: T,
124 ) -> Self {
125 self.0.request.solving_mode = v.into();
126 self
127 }
128
129 pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
131 mut self,
132 v: T,
133 ) -> Self {
134 self.0.request.search_mode = v.into();
135 self
136 }
137
138 pub fn set_injected_solution_constraint<
140 T: Into<std::option::Option<crate::model::InjectedSolutionConstraint>>,
141 >(
142 mut self,
143 v: T,
144 ) -> Self {
145 self.0.request.injected_solution_constraint = v.into();
146 self
147 }
148
149 pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
151 mut self,
152 v: T,
153 ) -> Self {
154 self.0.request.interpret_injected_solutions_using_labels = v.into();
155 self
156 }
157
158 pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
160 self.0.request.consider_road_traffic = v.into();
161 self
162 }
163
164 pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
166 self.0.request.populate_polylines = v.into();
167 self
168 }
169
170 pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
172 self.0.request.populate_transition_polylines = v.into();
173 self
174 }
175
176 pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
178 mut self,
179 v: T,
180 ) -> Self {
181 self.0
182 .request
183 .allow_large_deadline_despite_interruption_risk = v.into();
184 self
185 }
186
187 pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
189 self.0.request.use_geodesic_distances = v.into();
190 self
191 }
192
193 pub fn set_geodesic_meters_per_second<T: Into<std::option::Option<f64>>>(
195 mut self,
196 v: T,
197 ) -> Self {
198 self.0.request.geodesic_meters_per_second = v.into();
199 self
200 }
201
202 pub fn set_max_validation_errors<T: Into<std::option::Option<i32>>>(
204 mut self,
205 v: T,
206 ) -> Self {
207 self.0.request.max_validation_errors = v.into();
208 self
209 }
210
211 pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
213 self.0.request.label = v.into();
214 self
215 }
216
217 pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
219 self.0.request.populate_travel_step_polylines = v.into();
220 self
221 }
222
223 pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
225 where
226 T: std::iter::IntoIterator<Item = V>,
227 V: std::convert::Into<crate::model::ShipmentRoute>,
228 {
229 use std::iter::Iterator;
230 self.0.request.injected_first_solution_routes =
231 v.into_iter().map(|i| i.into()).collect();
232 self
233 }
234
235 pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
237 where
238 T: std::iter::IntoIterator<Item = V>,
239 V: std::convert::Into<crate::model::ShipmentRoute>,
240 {
241 use std::iter::Iterator;
242 self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
243 self
244 }
245 }
246
247 #[doc(hidden)]
248 impl gax::options::internal::RequestBuilder for OptimizeTours {
249 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
250 &mut self.0.options
251 }
252 }
253
254 #[derive(Clone, Debug)]
256 pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);
257
258 impl BatchOptimizeTours {
259 pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::FleetRouting>) -> Self {
260 Self(RequestBuilder::new(stub))
261 }
262
263 pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
265 mut self,
266 v: V,
267 ) -> Self {
268 self.0.request = v.into();
269 self
270 }
271
272 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
274 self.0.options = v.into();
275 self
276 }
277
278 pub async fn send(self) -> Result<longrunning::model::Operation> {
285 (*self.0.stub)
286 .batch_optimize_tours(self.0.request, self.0.options)
287 .await
288 .map(gax::response::Response::into_body)
289 }
290
291 pub fn poller(
293 self,
294 ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
295 {
296 type Operation = lro::Operation<
297 crate::model::BatchOptimizeToursResponse,
298 crate::model::AsyncModelMetadata,
299 >;
300 let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
301 let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
302
303 let stub = self.0.stub.clone();
304 let mut options = self.0.options.clone();
305 options.set_retry_policy(gax::retry_policy::NeverRetry);
306 let query = move |name| {
307 let stub = stub.clone();
308 let options = options.clone();
309 async {
310 let op = GetOperation::new(stub)
311 .set_name(name)
312 .with_options(options)
313 .send()
314 .await?;
315 Ok(Operation::new(op))
316 }
317 };
318
319 let start = move || async {
320 let op = self.send().await?;
321 Ok(Operation::new(op))
322 };
323
324 lro::new_poller(polling_error_policy, polling_backoff_policy, start, query)
325 }
326
327 pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
329 self.0.request.parent = v.into();
330 self
331 }
332
333 pub fn set_model_configs<T, V>(mut self, v: T) -> Self
335 where
336 T: std::iter::IntoIterator<Item = V>,
337 V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
338 {
339 use std::iter::Iterator;
340 self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
341 self
342 }
343 }
344
345 #[doc(hidden)]
346 impl gax::options::internal::RequestBuilder for BatchOptimizeTours {
347 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
348 &mut self.0.options
349 }
350 }
351
352 #[derive(Clone, Debug)]
354 pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
355
356 impl GetOperation {
357 pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::FleetRouting>) -> Self {
358 Self(RequestBuilder::new(stub))
359 }
360
361 pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
363 mut self,
364 v: V,
365 ) -> Self {
366 self.0.request = v.into();
367 self
368 }
369
370 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
372 self.0.options = v.into();
373 self
374 }
375
376 pub async fn send(self) -> Result<longrunning::model::Operation> {
378 (*self.0.stub)
379 .get_operation(self.0.request, self.0.options)
380 .await
381 .map(gax::response::Response::into_body)
382 }
383
384 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
386 self.0.request.name = v.into();
387 self
388 }
389 }
390
391 #[doc(hidden)]
392 impl gax::options::internal::RequestBuilder for GetOperation {
393 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
394 &mut self.0.options
395 }
396 }
397}