google-maps-routeoptimization-v1 1.0.0

Google Cloud Client Libraries for Rust - Route Optimization API
Documentation
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::bare_urls)]
#![allow(rustdoc::broken_intra_doc_links)]
#![allow(rustdoc::invalid_html_tags)]
#![allow(rustdoc::redundant_explicit_links)]

/// Implements a client for the Route Optimization API.
///
/// # Example
/// ```
/// # use google_maps_routeoptimization_v1::client::RouteOptimization;
/// async fn sample(
/// ) -> anyhow::Result<()> {
///     let client = RouteOptimization::builder().build().await?;
///     let response = client.optimize_tours()
///         /* set fields */
///         .send().await?;
///     println!("response {:?}", response);
///     Ok(())
/// }
/// ```
///
/// # Service Description
///
/// A service for optimizing vehicle tours.
///
/// Validity of certain types of fields:
///
/// * `google.protobuf.Timestamp`
///   * Times are in Unix time: seconds since 1970-01-01T00:00:00+00:00.
///   * seconds must be in [0, 253402300799],
///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
///   * nanos must be unset or set to 0.
/// * `google.protobuf.Duration`
///   * seconds must be in [0, 253402300799],
///     i.e. in [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
///   * nanos must be unset or set to 0.
/// * `google.type.LatLng`
///   * latitude must be in [-90.0, 90.0].
///   * longitude must be in [-180.0, 180.0].
///   * at least one of latitude and longitude must be non-zero.
///
/// # Configuration
///
/// To configure `RouteOptimization` use the `with_*` methods in the type returned
/// by [builder()][RouteOptimization::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://routeoptimization.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
///   with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::route_optimization::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::route_optimization::ClientBuilder::with_credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `RouteOptimization` holds a connection pool internally, it is advised to
/// create one and reuse it. You do not need to wrap `RouteOptimization` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct RouteOptimization {
    inner: std::sync::Arc<dyn super::stub::dynamic::RouteOptimization>,
}

impl RouteOptimization {
    /// Returns a builder for [RouteOptimization].
    ///
    /// ```
    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// let client = RouteOptimization::builder().build().await?;
    /// # Ok(()) }
    /// ```
    pub fn builder() -> super::builder::route_optimization::ClientBuilder {
        crate::new_client_builder(super::builder::route_optimization::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
    where
        T: super::stub::RouteOptimization + 'static,
    {
        Self { inner: stub.into() }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::RouteOptimization>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::RouteOptimization> {
        super::transport::RouteOptimization::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::RouteOptimization> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::RouteOptimization::new)
    }

    /// Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
    /// `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of
    /// routes to be performed by vehicles minimizing the overall cost.
    ///
    /// A `ShipmentModel` model consists mainly of `Shipment`s that need to be
    /// carried out and `Vehicle`s that can be used to transport the `Shipment`s.
    /// The `ShipmentRoute`s assign `Shipment`s to `Vehicle`s. More specifically,
    /// they assign a series of `Visit`s to each vehicle, where a `Visit`
    /// corresponds to a `VisitRequest`, which is a pickup or delivery for a
    /// `Shipment`.
    ///
    /// The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that
    /// minimizes the total cost where cost has many components defined in the
    /// `ShipmentModel`.
    ///
    /// # Example
    /// ```
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// use google_maps_routeoptimization_v1::Result;
    /// async fn sample(
    ///    client: &RouteOptimization
    /// ) -> Result<()> {
    ///     let response = client.optimize_tours()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn optimize_tours(&self) -> super::builder::route_optimization::OptimizeTours {
        super::builder::route_optimization::OptimizeTours::new(self.inner.clone())
    }

    /// Optimizes vehicle tours for one or more `OptimizeToursRequest`
    /// messages as a batch.
    ///
    /// This method is a Long Running Operation (LRO). The inputs for optimization
    /// (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse`
    /// messages) are read from and written to Cloud Storage in user-specified
    /// format. Like the `OptimizeTours` method, each `OptimizeToursRequest`
    /// contains a `ShipmentModel` and returns an `OptimizeToursResponse`
    /// containing `ShipmentRoute` fields, which are a set of routes to be
    /// performed by vehicles minimizing the overall cost.
    ///
    /// The user can poll `operations.get` to check the status of the LRO:
    ///
    /// If the LRO `done` field is false, then at least one request is still
    /// being processed. Other requests may have completed successfully and their
    /// results are available in Cloud Storage.
    ///
    /// If the LRO's `done` field is true, then all requests have been processed.
    /// Any successfully processed requests will have their results available in
    /// Cloud Storage. Any requests that failed will not have their results
    /// available in Cloud Storage. If the LRO's `error` field is set, then it
    /// contains the error from one of the failed requests.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// use google_cloud_lro::Poller;
    /// use google_maps_routeoptimization_v1::Result;
    /// async fn sample(
    ///    client: &RouteOptimization
    /// ) -> Result<()> {
    ///     let response = client.batch_optimize_tours()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn batch_optimize_tours(&self) -> super::builder::route_optimization::BatchOptimizeTours {
        super::builder::route_optimization::BatchOptimizeTours::new(self.inner.clone())
    }

    /// This is a variant of the
    /// [OptimizeTours][google.maps.routeoptimization.v1.RouteOptimization.OptimizeTours]
    /// method designed for
    /// optimizations with large timeout values. It should be preferred over the
    /// `OptimizeTours` method for optimizations that take longer than
    /// a few minutes.
    ///
    /// The returned [long-running operation][google.longrunning.Operation] (LRO)
    /// will have a name of the format
    /// `<parent>/operations/<operation_id>` and can be used to track
    /// progress of the computation. The
    /// [metadata][google.longrunning.Operation.metadata] field type is
    /// [OptimizeToursLongRunningMetadata][google.maps.routeoptimization.v1.OptimizeToursLongRunningMetadata].
    /// The [response][google.longrunning.Operation.response] field type is
    /// [OptimizeToursResponse][google.maps.routeoptimization.v1.OptimizeToursResponse],
    /// if successful.
    ///
    /// Experimental: See
    /// <https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request>
    /// for more details.
    ///
    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
    /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
    /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
    /// [google.maps.routeoptimization.v1.OptimizeToursLongRunningMetadata]: crate::model::OptimizeToursLongRunningMetadata
    /// [google.maps.routeoptimization.v1.OptimizeToursResponse]: crate::model::OptimizeToursResponse
    /// [google.maps.routeoptimization.v1.RouteOptimization.OptimizeTours]: crate::client::RouteOptimization::optimize_tours
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// use google_cloud_lro::Poller;
    /// use google_maps_routeoptimization_v1::Result;
    /// async fn sample(
    ///    client: &RouteOptimization
    /// ) -> Result<()> {
    ///     let response = client.optimize_tours_long_running()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn optimize_tours_long_running(
        &self,
    ) -> super::builder::route_optimization::OptimizeToursLongRunning {
        super::builder::route_optimization::OptimizeToursLongRunning::new(self.inner.clone())
    }

    /// This is a variant of the
    /// [OptimizeToursLongRunning][google.maps.routeoptimization.v1.RouteOptimization.OptimizeToursLongRunning]
    /// method designed for optimizations with large timeout values and large
    /// input/output sizes.
    ///
    /// The client specifies the URI of the `OptimizeToursRequest` stored
    /// in Google Cloud Storage and the server writes the `OptimizeToursResponse`
    /// to a client-specified Google Cloud Storage URI.
    ///
    /// This method should be preferred over the `OptimizeTours` method for
    /// optimizations that take longer than a few minutes and input/output sizes
    /// that are larger than 8MB, though it can be used for shorter and smaller
    /// optimizations as well.
    ///
    /// The returned [long-running operation][google.longrunning.Operation] (LRO)
    /// will have a name of the format
    /// `<parent>/operations/<operation_id>` and can be used to track
    /// progress of the computation. The
    /// [metadata][google.longrunning.Operation.metadata] field type is
    /// [OptimizeToursLongRunningMetadata][google.maps.routeoptimization.v1.OptimizeToursUriMetadata].
    /// The [response][google.longrunning.Operation.response] field type is
    /// [OptimizeToursUriResponse][google.maps.routeoptimization.v1.OptimizeToursUriResponse],
    /// if successful.
    ///
    /// Experimental: See
    /// <https://developers.google.com/maps/tt/route-optimization/experimental/otlr/make-request>
    /// for more details.
    ///
    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
    /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
    /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
    /// [google.maps.routeoptimization.v1.OptimizeToursUriMetadata]: crate::model::OptimizeToursUriMetadata
    /// [google.maps.routeoptimization.v1.OptimizeToursUriResponse]: crate::model::OptimizeToursUriResponse
    /// [google.maps.routeoptimization.v1.RouteOptimization.OptimizeToursLongRunning]: crate::client::RouteOptimization::optimize_tours_long_running
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    ///
    /// # Example
    /// ```
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// use google_cloud_lro::Poller;
    /// use google_maps_routeoptimization_v1::Result;
    /// async fn sample(
    ///    client: &RouteOptimization
    /// ) -> Result<()> {
    ///     let response = client.optimize_tours_uri()
    ///         /* set fields */
    ///         .poller().until_done().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn optimize_tours_uri(&self) -> super::builder::route_optimization::OptimizeToursUri {
        super::builder::route_optimization::OptimizeToursUri::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
    ///
    /// # Example
    /// ```
    /// # use google_maps_routeoptimization_v1::client::RouteOptimization;
    /// use google_maps_routeoptimization_v1::Result;
    /// async fn sample(
    ///    client: &RouteOptimization
    /// ) -> Result<()> {
    ///     let response = client.get_operation()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn get_operation(&self) -> super::builder::route_optimization::GetOperation {
        super::builder::route_optimization::GetOperation::new(self.inner.clone())
    }
}