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
19use crate::Result;
20use std::sync::Arc;
21
22/// Implements a client for the Cloud Optimization API.
23///
24/// # Example
25/// ```
26/// # tokio_test::block_on(async {
27/// # use google_cloud_optimization_v1::client::FleetRouting;
28/// let client = FleetRouting::builder().build().await?;
29/// // use `client` to make requests to the {Codec.APITitle}}.
30/// # gax::Result::<()>::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::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 the reuse it.  You do not need to wrap `FleetRouting` in
77/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
78/// internally.
79#[derive(Clone, Debug)]
80pub struct FleetRouting {
81    inner: Arc<dyn super::stub::dynamic::FleetRouting>,
82}
83
84impl FleetRouting {
85    /// Returns a builder for [FleetRouting].
86    ///
87    /// ```
88    /// # tokio_test::block_on(async {
89    /// # use google_cloud_optimization_v1::client::FleetRouting;
90    /// let client = FleetRouting::builder().build().await?;
91    /// # gax::Result::<()>::Ok(()) });
92    /// ```
93    pub fn builder() -> super::builder::fleet_routing::ClientBuilder {
94        gax::client_builder::internal::new_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: Arc::new(stub),
107        }
108    }
109
110    pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
111        let inner = Self::build_inner(config).await?;
112        Ok(Self { inner })
113    }
114
115    async fn build_inner(
116        conf: gaxi::options::ClientConfig,
117    ) -> Result<Arc<dyn super::stub::dynamic::FleetRouting>> {
118        if gaxi::options::tracing_enabled(&conf) {
119            return Ok(Arc::new(Self::build_with_tracing(conf).await?));
120        }
121        Ok(Arc::new(Self::build_transport(conf).await?))
122    }
123
124    async fn build_transport(
125        conf: gaxi::options::ClientConfig,
126    ) -> Result<impl super::stub::FleetRouting> {
127        super::transport::FleetRouting::new(conf).await
128    }
129
130    async fn build_with_tracing(
131        conf: gaxi::options::ClientConfig,
132    ) -> Result<impl super::stub::FleetRouting> {
133        Self::build_transport(conf)
134            .await
135            .map(super::tracing::FleetRouting::new)
136    }
137
138    /// Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
139    /// `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
140    /// routes to be performed by vehicles minimizing the overall cost.
141    ///
142    /// A `ShipmentModel` model consists mainly of `Shipment`s that need to be
143    /// carried out and `Vehicle`s that can be used to transport the `Shipment`s.
144    /// The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
145    /// they assign a series of `Visit`s to each vehicle, where a `Visit`
146    /// corresponds to a `VisitRequest`, which is a pickup or delivery for a
147    /// `Shipment`.
148    ///
149    /// The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
150    /// minimizes the total cost where cost has many components defined in the
151    /// `ShipmentModel`.
152    pub fn optimize_tours(
153        &self,
154        parent: impl Into<std::string::String>,
155    ) -> super::builder::fleet_routing::OptimizeTours {
156        super::builder::fleet_routing::OptimizeTours::new(self.inner.clone())
157            .set_parent(parent.into())
158    }
159
160    /// Optimizes vehicle tours for one or more `OptimizeToursRequest`
161    /// messages as a batch.
162    ///
163    /// This method is a Long Running Operation (LRO). The inputs for optimization
164    /// (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
165    /// messages) are read/written from/to Cloud Storage in user-specified
166    /// format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
167    /// contains a `ShipmentModel` and returns an `OptimizeToursResponse`
168    /// containing `ShipmentRoute`s, which are a set of routes to be performed by
169    /// vehicles minimizing the overall cost.
170    ///
171    /// # Long running operations
172    ///
173    /// This method is used to start, and/or poll a [long-running Operation].
174    /// The [Working with long-running operations] chapter in the [user guide]
175    /// covers these operations in detail.
176    ///
177    /// [long-running operation]: https://google.aip.dev/151
178    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
179    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
180    pub fn batch_optimize_tours(
181        &self,
182        parent: impl Into<std::string::String>,
183    ) -> super::builder::fleet_routing::BatchOptimizeTours {
184        super::builder::fleet_routing::BatchOptimizeTours::new(self.inner.clone())
185            .set_parent(parent.into())
186    }
187
188    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
189    ///
190    /// [google.longrunning.Operations]: longrunning::client::Operations
191    pub fn get_operation(
192        &self,
193        name: impl Into<std::string::String>,
194    ) -> super::builder::fleet_routing::GetOperation {
195        super::builder::fleet_routing::GetOperation::new(self.inner.clone()).set_name(name.into())
196    }
197}