Skip to main content

google_maps_routeoptimization_v1/
client.rs

1// Copyright 2026 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Route Optimization API.
22///
23/// # Example
24/// ```
25/// # use google_maps_routeoptimization_v1::client::RouteOptimization;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28///     let client = RouteOptimization::builder().build().await?;
29///     let response = client.optimize_tours()
30///         /* set fields */
31///         .send().await?;
32///     println!("response {:?}", response);
33///     Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// A service for optimizing vehicle tours.
40///
41/// Validity of certain types of fields:
42///
43/// * `google.protobuf.Timestamp`
44///   * Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00.
45///   * seconds must be in [0, 253402300799],
46///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
47///   * nanos must be unset or set to 0.
48/// * `google.protobuf.Duration`
49///   * seconds must be in [0, 253402300799],
50///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
51///   * nanos must be unset or set to 0.
52/// * `google.type.LatLng`
53///   * latitude must be in [-90.0, 90.0].
54///   * longitude must be in [-180.0, 180.0].
55///   * at least one of latitude and longitude must be non-zero.
56///
57/// # Configuration
58///
59/// To configure `RouteOptimization` use the `with_*` methods in the type returned
60/// by [builder()][RouteOptimization::builder]. The default configuration should
61/// work for most applications. Common configuration changes include
62///
63/// * [with_endpoint()]: by default this client uses the global default endpoint
64///   (`https://routeoptimization.googleapis.com`). Applications using regional
65///   endpoints or running in restricted networks (e.g. a network configured
66///   with [Private Google Access with VPC Service Controls]) may want to
67///   override this default.
68/// * [with_credentials()]: by default this client uses
69///   [Application Default Credentials]. Applications using custom
70///   authentication may need to override this default.
71///
72/// [with_endpoint()]: super::builder::route_optimization::ClientBuilder::with_endpoint
73/// [with_credentials()]: super::builder::route_optimization::ClientBuilder::with_credentials
74/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
75/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
76///
77/// # Pooling and Cloning
78///
79/// `RouteOptimization` holds a connection pool internally, it is advised to
80/// create one and reuse it. You do not need to wrap `RouteOptimization` in
81/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
82/// already uses an `Arc` internally.
83#[derive(Clone, Debug)]
84pub struct RouteOptimization {
85    inner: std::sync::Arc<dyn super::stub::dynamic::RouteOptimization>,
86}
87
88impl RouteOptimization {
89    /// Returns a builder for [RouteOptimization].
90    ///
91    /// ```
92    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
93    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
94    /// let client = RouteOptimization::builder().build().await?;
95    /// # Ok(()) }
96    /// ```
97    pub fn builder() -> super::builder::route_optimization::ClientBuilder {
98        crate::new_client_builder(super::builder::route_optimization::client::Factory)
99    }
100
101    /// Creates a new client from the provided stub.
102    ///
103    /// The most common case for calling this function is in tests mocking the
104    /// client's behavior.
105    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
106    where
107        T: super::stub::RouteOptimization + 'static,
108    {
109        Self { inner: stub.into() }
110    }
111
112    pub(crate) async fn new(
113        config: gaxi::options::ClientConfig,
114    ) -> crate::ClientBuilderResult<Self> {
115        let inner = Self::build_inner(config).await?;
116        Ok(Self { inner })
117    }
118
119    async fn build_inner(
120        conf: gaxi::options::ClientConfig,
121    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::RouteOptimization>>
122    {
123        if gaxi::options::tracing_enabled(&conf) {
124            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
125        }
126        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
127    }
128
129    async fn build_transport(
130        conf: gaxi::options::ClientConfig,
131    ) -> crate::ClientBuilderResult<impl super::stub::RouteOptimization> {
132        super::transport::RouteOptimization::new(conf).await
133    }
134
135    async fn build_with_tracing(
136        conf: gaxi::options::ClientConfig,
137    ) -> crate::ClientBuilderResult<impl super::stub::RouteOptimization> {
138        Self::build_transport(conf)
139            .await
140            .map(super::tracing::RouteOptimization::new)
141    }
142
143    /// Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
144    /// `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
145    /// routes to be performed by vehicles minimizing the overall cost.
146    ///
147    /// A `ShipmentModel` model consists mainly of `Shipment`s that need to be
148    /// carried out and `Vehicle`s that can be used to transport the `Shipment`s.
149    /// The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
150    /// they assign a series of `Visit`s to each vehicle, where a `Visit`
151    /// corresponds to a `VisitRequest`, which is a pickup or delivery for a
152    /// `Shipment`.
153    ///
154    /// The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
155    /// minimizes the total cost where cost has many components defined in the
156    /// `ShipmentModel`.
157    ///
158    /// # Example
159    /// ```
160    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
161    /// use google_maps_routeoptimization_v1::Result;
162    /// async fn sample(
163    ///    client: &RouteOptimization
164    /// ) -> Result<()> {
165    ///     let response = client.optimize_tours()
166    ///         /* set fields */
167    ///         .send().await?;
168    ///     println!("response {:?}", response);
169    ///     Ok(())
170    /// }
171    /// ```
172    pub fn optimize_tours(&self) -> super::builder::route_optimization::OptimizeTours {
173        super::builder::route_optimization::OptimizeTours::new(self.inner.clone())
174    }
175
176    /// Optimizes vehicle tours for one or more `OptimizeToursRequest`
177    /// messages as a batch.
178    ///
179    /// This method is a Long Running Operation (LRO). The inputs for optimization
180    /// (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
181    /// messages) are read from and written to Cloud Storage in user-specified
182    /// format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
183    /// contains a `ShipmentModel` and returns an `OptimizeToursResponse`
184    /// containing `ShipmentRoute` fields, which are a set of routes to be
185    /// performed by vehicles minimizing the overall cost.
186    ///
187    /// The user can poll `operations.get` to check the status of the LRO:
188    ///
189    /// If the LRO `done` field is false, then at least one request is still
190    /// being processed. Other requests may have completed successfully and their
191    /// results are available in Cloud Storage.
192    ///
193    /// If the LRO's `done` field is true, then all requests have been processed.
194    /// Any successfully processed requests will have their results available in
195    /// Cloud Storage. Any requests that failed will not have their results
196    /// available in Cloud Storage. If the LRO's `error` field is set, then it
197    /// contains the error from one of the failed requests.
198    ///
199    /// # Long running operations
200    ///
201    /// This method is used to start, and/or poll a [long-running Operation].
202    /// The [Working with long-running operations] chapter in the [user guide]
203    /// covers these operations in detail.
204    ///
205    /// [long-running operation]: https://google.aip.dev/151
206    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
207    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
208    ///
209    /// # Example
210    /// ```
211    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
212    /// use google_cloud_lro::Poller;
213    /// use google_maps_routeoptimization_v1::Result;
214    /// async fn sample(
215    ///    client: &RouteOptimization
216    /// ) -> Result<()> {
217    ///     let response = client.batch_optimize_tours()
218    ///         /* set fields */
219    ///         .poller().until_done().await?;
220    ///     println!("response {:?}", response);
221    ///     Ok(())
222    /// }
223    /// ```
224    pub fn batch_optimize_tours(&self) -> super::builder::route_optimization::BatchOptimizeTours {
225        super::builder::route_optimization::BatchOptimizeTours::new(self.inner.clone())
226    }
227
228    /// This is a variant of the
229    /// [OptimizeTours][google.maps.routeoptimization.v1.RouteOptimization.OptimizeTours]
230    /// method designed for
231    /// optimizations with large timeout values. It should be preferred over the
232    /// `OptimizeTours` method for optimizations that take longer than
233    /// a few minutes.
234    ///
235    /// The returned [long-running operation][google.longrunning.Operation] (LRO)
236    /// will have a name of the format
237    /// `<parent>/operations/<operation_id>` and can be used to track
238    /// progress of the computation. The
239    /// [metadata][google.longrunning.Operation.metadata] field type is
240    /// [OptimizeToursLongRunningMetadata][google.maps.routeoptimization.v1.OptimizeToursLongRunningMetadata].
241    /// The [response][google.longrunning.Operation.response] field type is
242    /// [OptimizeToursResponse][google.maps.routeoptimization.v1.OptimizeToursResponse],
243    /// if successful.
244    ///
245    /// Experimental: See
246    /// <https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request>
247    /// for more details.
248    ///
249    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
250    /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
251    /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
252    /// [google.maps.routeoptimization.v1.OptimizeToursLongRunningMetadata]: crate::model::OptimizeToursLongRunningMetadata
253    /// [google.maps.routeoptimization.v1.OptimizeToursResponse]: crate::model::OptimizeToursResponse
254    /// [google.maps.routeoptimization.v1.RouteOptimization.OptimizeTours]: crate::client::RouteOptimization::optimize_tours
255    ///
256    /// # Long running operations
257    ///
258    /// This method is used to start, and/or poll a [long-running Operation].
259    /// The [Working with long-running operations] chapter in the [user guide]
260    /// covers these operations in detail.
261    ///
262    /// [long-running operation]: https://google.aip.dev/151
263    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
264    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
265    ///
266    /// # Example
267    /// ```
268    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
269    /// use google_cloud_lro::Poller;
270    /// use google_maps_routeoptimization_v1::Result;
271    /// async fn sample(
272    ///    client: &RouteOptimization
273    /// ) -> Result<()> {
274    ///     let response = client.optimize_tours_long_running()
275    ///         /* set fields */
276    ///         .poller().until_done().await?;
277    ///     println!("response {:?}", response);
278    ///     Ok(())
279    /// }
280    /// ```
281    pub fn optimize_tours_long_running(
282        &self,
283    ) -> super::builder::route_optimization::OptimizeToursLongRunning {
284        super::builder::route_optimization::OptimizeToursLongRunning::new(self.inner.clone())
285    }
286
287    /// This is a variant of the
288    /// [OptimizeToursLongRunning][google.maps.routeoptimization.v1.RouteOptimization.OptimizeToursLongRunning]
289    /// method designed for optimizations with large timeout values and large
290    /// input/output sizes.
291    ///
292    /// The client specifies the URI of the `OptimizeToursRequest` stored
293    /// in Google Cloud Storage and the server writes the `OptimizeToursResponse`
294    /// to a client-specified Google Cloud Storage URI.
295    ///
296    /// This method should be preferred over the `OptimizeTours` method for
297    /// optimizations that take longer than a few minutes and input/output sizes
298    /// that are larger than 8MB, though it can be used for shorter and smaller
299    /// optimizations as well.
300    ///
301    /// The returned [long-running operation][google.longrunning.Operation] (LRO)
302    /// will have a name of the format
303    /// `<parent>/operations/<operation_id>` and can be used to track
304    /// progress of the computation. The
305    /// [metadata][google.longrunning.Operation.metadata] field type is
306    /// [OptimizeToursLongRunningMetadata][google.maps.routeoptimization.v1.OptimizeToursUriMetadata].
307    /// The [response][google.longrunning.Operation.response] field type is
308    /// [OptimizeToursUriResponse][google.maps.routeoptimization.v1.OptimizeToursUriResponse],
309    /// if successful.
310    ///
311    /// Experimental: See
312    /// <https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request>
313    /// for more details.
314    ///
315    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
316    /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
317    /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
318    /// [google.maps.routeoptimization.v1.OptimizeToursUriMetadata]: crate::model::OptimizeToursUriMetadata
319    /// [google.maps.routeoptimization.v1.OptimizeToursUriResponse]: crate::model::OptimizeToursUriResponse
320    /// [google.maps.routeoptimization.v1.RouteOptimization.OptimizeToursLongRunning]: crate::client::RouteOptimization::optimize_tours_long_running
321    ///
322    /// # Long running operations
323    ///
324    /// This method is used to start, and/or poll a [long-running Operation].
325    /// The [Working with long-running operations] chapter in the [user guide]
326    /// covers these operations in detail.
327    ///
328    /// [long-running operation]: https://google.aip.dev/151
329    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
330    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
331    ///
332    /// # Example
333    /// ```
334    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
335    /// use google_cloud_lro::Poller;
336    /// use google_maps_routeoptimization_v1::Result;
337    /// async fn sample(
338    ///    client: &RouteOptimization
339    /// ) -> Result<()> {
340    ///     let response = client.optimize_tours_uri()
341    ///         /* set fields */
342    ///         .poller().until_done().await?;
343    ///     println!("response {:?}", response);
344    ///     Ok(())
345    /// }
346    /// ```
347    pub fn optimize_tours_uri(&self) -> super::builder::route_optimization::OptimizeToursUri {
348        super::builder::route_optimization::OptimizeToursUri::new(self.inner.clone())
349    }
350
351    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
352    ///
353    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
354    ///
355    /// # Example
356    /// ```
357    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
358    /// use google_maps_routeoptimization_v1::Result;
359    /// async fn sample(
360    ///    client: &RouteOptimization
361    /// ) -> Result<()> {
362    ///     let response = client.get_operation()
363    ///         /* set fields */
364    ///         .send().await?;
365    ///     println!("response {:?}", response);
366    ///     Ok(())
367    /// }
368    /// ```
369    pub fn get_operation(&self) -> super::builder::route_optimization::GetOperation {
370        super::builder::route_optimization::GetOperation::new(self.inner.clone())
371    }
372}