Skip to main content

google_cloud_optimization_v1/
client.rs

1// Copyright 2025 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 Cloud Optimization API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_optimization_v1::client::FleetRouting;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28///     let client = FleetRouting::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 `FleetRouting` use the `with_*` methods in the type returned
60/// by [builder()][FleetRouting::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://cloudoptimization.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::fleet_routing::ClientBuilder::with_endpoint
73/// [with_credentials()]: super::builder::fleet_routing::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/// `FleetRouting` holds a connection pool internally, it is advised to
80/// create one and reuse it. You do not need to wrap `FleetRouting` 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 FleetRouting {
85    inner: std::sync::Arc<dyn super::stub::dynamic::FleetRouting>,
86}
87
88impl FleetRouting {
89    /// Returns a builder for [FleetRouting].
90    ///
91    /// ```
92    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
93    /// # use google_cloud_optimization_v1::client::FleetRouting;
94    /// let client = FleetRouting::builder().build().await?;
95    /// # Ok(()) }
96    /// ```
97    pub fn builder() -> super::builder::fleet_routing::ClientBuilder {
98        crate::new_client_builder(super::builder::fleet_routing::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::FleetRouting + '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::FleetRouting>> {
122        if gaxi::options::tracing_enabled(&conf) {
123            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
124        }
125        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
126    }
127
128    async fn build_transport(
129        conf: gaxi::options::ClientConfig,
130    ) -> crate::ClientBuilderResult<impl super::stub::FleetRouting> {
131        super::transport::FleetRouting::new(conf).await
132    }
133
134    async fn build_with_tracing(
135        conf: gaxi::options::ClientConfig,
136    ) -> crate::ClientBuilderResult<impl super::stub::FleetRouting> {
137        Self::build_transport(conf)
138            .await
139            .map(super::tracing::FleetRouting::new)
140    }
141
142    /// Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
143    /// `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
144    /// routes to be performed by vehicles minimizing the overall cost.
145    ///
146    /// A `ShipmentModel` model consists mainly of `Shipment`s that need to be
147    /// carried out and `Vehicle`s that can be used to transport the `Shipment`s.
148    /// The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
149    /// they assign a series of `Visit`s to each vehicle, where a `Visit`
150    /// corresponds to a `VisitRequest`, which is a pickup or delivery for a
151    /// `Shipment`.
152    ///
153    /// The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
154    /// minimizes the total cost where cost has many components defined in the
155    /// `ShipmentModel`.
156    ///
157    /// # Example
158    /// ```
159    /// # use google_cloud_optimization_v1::client::FleetRouting;
160    /// use google_cloud_optimization_v1::Result;
161    /// async fn sample(
162    ///    client: &FleetRouting
163    /// ) -> Result<()> {
164    ///     let response = client.optimize_tours()
165    ///         /* set fields */
166    ///         .send().await?;
167    ///     println!("response {:?}", response);
168    ///     Ok(())
169    /// }
170    /// ```
171    pub fn optimize_tours(&self) -> super::builder::fleet_routing::OptimizeTours {
172        super::builder::fleet_routing::OptimizeTours::new(self.inner.clone())
173    }
174
175    /// Optimizes vehicle tours for one or more `OptimizeToursRequest`
176    /// messages as a batch.
177    ///
178    /// This method is a Long Running Operation (LRO). The inputs for optimization
179    /// (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
180    /// messages) are read/written from/to Cloud Storage in user-specified
181    /// format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
182    /// contains a `ShipmentModel` and returns an `OptimizeToursResponse`
183    /// containing `ShipmentRoute`s, which are a set of routes to be performed by
184    /// vehicles minimizing the overall cost.
185    ///
186    /// # Long running operations
187    ///
188    /// This method is used to start, and/or poll a [long-running Operation].
189    /// The [Working with long-running operations] chapter in the [user guide]
190    /// covers these operations in detail.
191    ///
192    /// [long-running operation]: https://google.aip.dev/151
193    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
194    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
195    ///
196    /// # Example
197    /// ```
198    /// # use google_cloud_optimization_v1::client::FleetRouting;
199    /// use google_cloud_lro::Poller;
200    /// use google_cloud_optimization_v1::Result;
201    /// async fn sample(
202    ///    client: &FleetRouting
203    /// ) -> Result<()> {
204    ///     let response = client.batch_optimize_tours()
205    ///         /* set fields */
206    ///         .poller().until_done().await?;
207    ///     println!("response {:?}", response);
208    ///     Ok(())
209    /// }
210    /// ```
211    pub fn batch_optimize_tours(&self) -> super::builder::fleet_routing::BatchOptimizeTours {
212        super::builder::fleet_routing::BatchOptimizeTours::new(self.inner.clone())
213    }
214
215    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
216    ///
217    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
218    ///
219    /// # Example
220    /// ```
221    /// # use google_cloud_optimization_v1::client::FleetRouting;
222    /// use google_cloud_optimization_v1::Result;
223    /// async fn sample(
224    ///    client: &FleetRouting
225    /// ) -> Result<()> {
226    ///     let response = client.get_operation()
227    ///         /* set fields */
228    ///         .send().await?;
229    ///     println!("response {:?}", response);
230    ///     Ok(())
231    /// }
232    /// ```
233    pub fn get_operation(&self) -> super::builder::fleet_routing::GetOperation {
234        super::builder::fleet_routing::GetOperation::new(self.inner.clone())
235    }
236}