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::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Optimization API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_optimization_v1::client::FleetRouting;
24/// async fn sample(
25/// ) -> anyhow::Result<()> {
26///     let client = FleetRouting::builder().build().await?;
27///     let response = client.optimize_tours()
28///         /* set fields */
29///         .send().await?;
30///     println!("response {:?}", response);
31///     Ok(())
32/// }
33/// ```
34///
35/// # Service Description
36///
37/// A service for optimizing vehicle tours.
38///
39/// Validity of certain types of fields:
40///
41/// * `google.protobuf.Timestamp`
42///   * Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00.
43///   * seconds must be in [0, 253402300799],
44///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
45///   * nanos must be unset or set to 0.
46/// * `google.protobuf.Duration`
47///   * seconds must be in [0, 253402300799],
48///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
49///   * nanos must be unset or set to 0.
50/// * `google.type.LatLng`
51///   * latitude must be in [-90.0, 90.0].
52///   * longitude must be in [-180.0, 180.0].
53///   * at least one of latitude and longitude must be non-zero.
54///
55/// # Configuration
56///
57/// To configure `FleetRouting` use the `with_*` methods in the type returned
58/// by [builder()][FleetRouting::builder]. The default configuration should
59/// work for most applications. Common configuration changes include
60///
61/// * [with_endpoint()]: by default this client uses the global default endpoint
62///   (`https://cloudoptimization.googleapis.com`). Applications using regional
63///   endpoints or running in restricted networks (e.g. a network configured
64//    with [Private Google Access with VPC Service Controls]) may want to
65///   override this default.
66/// * [with_credentials()]: by default this client uses
67///   [Application Default Credentials]. Applications using custom
68///   authentication may need to override this default.
69///
70/// [with_endpoint()]: super::builder::fleet_routing::ClientBuilder::with_endpoint
71/// [with_credentials()]: super::builder::fleet_routing::ClientBuilder::with_credentials
72/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
73/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
74///
75/// # Pooling and Cloning
76///
77/// `FleetRouting` holds a connection pool internally, it is advised to
78/// create one and reuse it. You do not need to wrap `FleetRouting` in
79/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
80/// already uses an `Arc` internally.
81#[derive(Clone, Debug)]
82pub struct FleetRouting {
83    inner: std::sync::Arc<dyn super::stub::dynamic::FleetRouting>,
84}
85
86impl FleetRouting {
87    /// Returns a builder for [FleetRouting].
88    ///
89    /// ```
90    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
91    /// # use google_cloud_optimization_v1::client::FleetRouting;
92    /// let client = FleetRouting::builder().build().await?;
93    /// # Ok(()) }
94    /// ```
95    pub fn builder() -> super::builder::fleet_routing::ClientBuilder {
96        crate::new_client_builder(super::builder::fleet_routing::client::Factory)
97    }
98
99    /// Creates a new client from the provided stub.
100    ///
101    /// The most common case for calling this function is in tests mocking the
102    /// client's behavior.
103    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
104    where
105        T: super::stub::FleetRouting + 'static,
106    {
107        Self { inner: stub.into() }
108    }
109
110    pub(crate) async fn new(
111        config: gaxi::options::ClientConfig,
112    ) -> crate::ClientBuilderResult<Self> {
113        let inner = Self::build_inner(config).await?;
114        Ok(Self { inner })
115    }
116
117    async fn build_inner(
118        conf: gaxi::options::ClientConfig,
119    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::FleetRouting>> {
120        if gaxi::options::tracing_enabled(&conf) {
121            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
122        }
123        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
124    }
125
126    async fn build_transport(
127        conf: gaxi::options::ClientConfig,
128    ) -> crate::ClientBuilderResult<impl super::stub::FleetRouting> {
129        super::transport::FleetRouting::new(conf).await
130    }
131
132    async fn build_with_tracing(
133        conf: gaxi::options::ClientConfig,
134    ) -> crate::ClientBuilderResult<impl super::stub::FleetRouting> {
135        Self::build_transport(conf)
136            .await
137            .map(super::tracing::FleetRouting::new)
138    }
139
140    /// Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
141    /// `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
142    /// routes to be performed by vehicles minimizing the overall cost.
143    ///
144    /// A `ShipmentModel` model consists mainly of `Shipment`s that need to be
145    /// carried out and `Vehicle`s that can be used to transport the `Shipment`s.
146    /// The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
147    /// they assign a series of `Visit`s to each vehicle, where a `Visit`
148    /// corresponds to a `VisitRequest`, which is a pickup or delivery for a
149    /// `Shipment`.
150    ///
151    /// The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
152    /// minimizes the total cost where cost has many components defined in the
153    /// `ShipmentModel`.
154    ///
155    /// # Example
156    /// ```
157    /// # use google_cloud_optimization_v1::client::FleetRouting;
158    /// use google_cloud_optimization_v1::Result;
159    /// async fn sample(
160    ///    client: &FleetRouting
161    /// ) -> Result<()> {
162    ///     let response = client.optimize_tours()
163    ///         /* set fields */
164    ///         .send().await?;
165    ///     println!("response {:?}", response);
166    ///     Ok(())
167    /// }
168    /// ```
169    pub fn optimize_tours(&self) -> super::builder::fleet_routing::OptimizeTours {
170        super::builder::fleet_routing::OptimizeTours::new(self.inner.clone())
171    }
172
173    /// Optimizes vehicle tours for one or more `OptimizeToursRequest`
174    /// messages as a batch.
175    ///
176    /// This method is a Long Running Operation (LRO). The inputs for optimization
177    /// (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
178    /// messages) are read/written from/to Cloud Storage in user-specified
179    /// format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
180    /// contains a `ShipmentModel` and returns an `OptimizeToursResponse`
181    /// containing `ShipmentRoute`s, which are a set of routes to be performed by
182    /// vehicles minimizing the overall cost.
183    ///
184    /// # Long running operations
185    ///
186    /// This method is used to start, and/or poll a [long-running Operation].
187    /// The [Working with long-running operations] chapter in the [user guide]
188    /// covers these operations in detail.
189    ///
190    /// [long-running operation]: https://google.aip.dev/151
191    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
192    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
193    ///
194    /// # Example
195    /// ```
196    /// # use google_cloud_optimization_v1::client::FleetRouting;
197    /// use google_cloud_lro::Poller;
198    /// use google_cloud_optimization_v1::Result;
199    /// async fn sample(
200    ///    client: &FleetRouting
201    /// ) -> Result<()> {
202    ///     let response = client.batch_optimize_tours()
203    ///         /* set fields */
204    ///         .poller().until_done().await?;
205    ///     println!("response {:?}", response);
206    ///     Ok(())
207    /// }
208    /// ```
209    pub fn batch_optimize_tours(&self) -> super::builder::fleet_routing::BatchOptimizeTours {
210        super::builder::fleet_routing::BatchOptimizeTours::new(self.inner.clone())
211    }
212
213    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
214    ///
215    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
216    ///
217    /// # Example
218    /// ```
219    /// # use google_cloud_optimization_v1::client::FleetRouting;
220    /// use google_cloud_optimization_v1::Result;
221    /// async fn sample(
222    ///    client: &FleetRouting
223    /// ) -> Result<()> {
224    ///     let response = client.get_operation()
225    ///         /* set fields */
226    ///         .send().await?;
227    ///     println!("response {:?}", response);
228    ///     Ok(())
229    /// }
230    /// ```
231    pub fn get_operation(&self) -> super::builder::fleet_routing::GetOperation {
232        super::builder::fleet_routing::GetOperation::new(self.inner.clone())
233    }
234}