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