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() -> Result<(), Box<dyn std::error::Error>> {
25///     let client = FleetRouting::builder().build().await?;
26///     let response = client.optimize_tours()
27///         /* set fields */
28///         .send().await?;
29///     println!("response {:?}", response);
30/// # Ok(()) }
31/// ```
32///
33/// # Service Description
34///
35/// A service for optimizing vehicle tours.
36///
37/// Validity of certain types of fields:
38///
39/// * `google.protobuf.Timestamp`
40///   * Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00.
41///   * seconds must be in [0, 253402300799],
42///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
43///   * nanos must be unset or set to 0.
44/// * `google.protobuf.Duration`
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.type.LatLng`
49///   * latitude must be in [-90.0, 90.0].
50///   * longitude must be in [-180.0, 180.0].
51///   * at least one of latitude and longitude must be non-zero.
52///
53/// # Configuration
54///
55/// To configure `FleetRouting` use the `with_*` methods in the type returned
56/// by [builder()][FleetRouting::builder]. The default configuration should
57/// work for most applications. Common configuration changes include
58///
59/// * [with_endpoint()]: by default this client uses the global default endpoint
60///   (`https://cloudoptimization.googleapis.com`). Applications using regional
61///   endpoints or running in restricted networks (e.g. a network configured
62//    with [Private Google Access with VPC Service Controls]) may want to
63///   override this default.
64/// * [with_credentials()]: by default this client uses
65///   [Application Default Credentials]. Applications using custom
66///   authentication may need to override this default.
67///
68/// [with_endpoint()]: super::builder::fleet_routing::ClientBuilder::with_endpoint
69/// [with_credentials()]: super::builder::fleet_routing::ClientBuilder::with_credentials
70/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
71/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
72///
73/// # Pooling and Cloning
74///
75/// `FleetRouting` holds a connection pool internally, it is advised to
76/// create one and reuse it. You do not need to wrap `FleetRouting` in
77/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
78/// already uses an `Arc` internally.
79#[derive(Clone, Debug)]
80pub struct FleetRouting {
81    inner: std::sync::Arc<dyn super::stub::dynamic::FleetRouting>,
82}
83
84impl FleetRouting {
85    /// Returns a builder for [FleetRouting].
86    ///
87    /// ```
88    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
89    /// # use google_cloud_optimization_v1::client::FleetRouting;
90    /// let client = FleetRouting::builder().build().await?;
91    /// # Ok(()) }
92    /// ```
93    pub fn builder() -> super::builder::fleet_routing::ClientBuilder {
94        crate::new_client_builder(super::builder::fleet_routing::client::Factory)
95    }
96
97    /// Creates a new client from the provided stub.
98    ///
99    /// The most common case for calling this function is in tests mocking the
100    /// client's behavior.
101    pub fn from_stub<T>(stub: T) -> Self
102    where
103        T: super::stub::FleetRouting + 'static,
104    {
105        Self {
106            inner: std::sync::Arc::new(stub),
107        }
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}