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