google-maps-routing-v2 1.1.0

Google Cloud Client Libraries for Rust - Routes 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.

/// Request and client builders for [Routes][crate::client::Routes].
pub mod routes {
    use crate::Result;

    /// A builder for [Routes][crate::client::Routes].
    ///
    /// ```
    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
    /// # use google_maps_routing_v2::*;
    /// # use builder::routes::ClientBuilder;
    /// # use client::Routes;
    /// let builder : ClientBuilder = Routes::builder();
    /// let client = builder
    ///     .with_endpoint("https://routes.googleapis.com")
    ///     .build().await?;
    /// # Ok(()) }
    /// ```
    pub type ClientBuilder = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;

    pub(crate) mod client {
        use super::super::super::client::Routes;
        pub struct Factory;
        impl crate::ClientFactory for Factory {
            type Client = Routes;
            type Credentials = gaxi::options::Credentials;
            async fn build(
                self,
                config: gaxi::options::ClientConfig,
            ) -> crate::ClientBuilderResult<Self::Client> {
                Self::Client::new(config).await
            }
        }
    }

    /// Common implementation for [crate::client::Routes] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::Routes>,
        request: R,
        options: crate::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Routes>) -> Self {
            Self {
                stub,
                request: R::default(),
                options: crate::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [Routes::compute_routes][crate::client::Routes::compute_routes] calls.
    ///
    /// # Example
    /// ```
    /// # use google_maps_routing_v2::builder::routes::ComputeRoutes;
    /// # async fn sample() -> google_maps_routing_v2::Result<()> {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # Ok(()) }
    ///
    /// fn prepare_request_builder() -> ComputeRoutes {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct ComputeRoutes(RequestBuilder<crate::model::ComputeRoutesRequest>);

    impl ComputeRoutes {
        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Routes>) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::ComputeRoutesRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::ComputeRoutesResponse> {
            (*self.0.stub)
                .compute_routes(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [origin][crate::model::ComputeRoutesRequest::origin].
        ///
        /// This is a **required** field for requests.
        pub fn set_origin<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Waypoint>,
        {
            self.0.request.origin = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [origin][crate::model::ComputeRoutesRequest::origin].
        ///
        /// This is a **required** field for requests.
        pub fn set_or_clear_origin<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Waypoint>,
        {
            self.0.request.origin = v.map(|x| x.into());
            self
        }

        /// Sets the value of [destination][crate::model::ComputeRoutesRequest::destination].
        ///
        /// This is a **required** field for requests.
        pub fn set_destination<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Waypoint>,
        {
            self.0.request.destination = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [destination][crate::model::ComputeRoutesRequest::destination].
        ///
        /// This is a **required** field for requests.
        pub fn set_or_clear_destination<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Waypoint>,
        {
            self.0.request.destination = v.map(|x| x.into());
            self
        }

        /// Sets the value of [intermediates][crate::model::ComputeRoutesRequest::intermediates].
        pub fn set_intermediates<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::Waypoint>,
        {
            use std::iter::Iterator;
            self.0.request.intermediates = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [travel_mode][crate::model::ComputeRoutesRequest::travel_mode].
        pub fn set_travel_mode<T: Into<crate::model::RouteTravelMode>>(mut self, v: T) -> Self {
            self.0.request.travel_mode = v.into();
            self
        }

        /// Sets the value of [routing_preference][crate::model::ComputeRoutesRequest::routing_preference].
        pub fn set_routing_preference<T: Into<crate::model::RoutingPreference>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.routing_preference = v.into();
            self
        }

        /// Sets the value of [polyline_quality][crate::model::ComputeRoutesRequest::polyline_quality].
        pub fn set_polyline_quality<T: Into<crate::model::PolylineQuality>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.polyline_quality = v.into();
            self
        }

        /// Sets the value of [polyline_encoding][crate::model::ComputeRoutesRequest::polyline_encoding].
        pub fn set_polyline_encoding<T: Into<crate::model::PolylineEncoding>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.polyline_encoding = v.into();
            self
        }

        /// Sets the value of [departure_time][crate::model::ComputeRoutesRequest::departure_time].
        pub fn set_departure_time<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<wkt::Timestamp>,
        {
            self.0.request.departure_time = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [departure_time][crate::model::ComputeRoutesRequest::departure_time].
        pub fn set_or_clear_departure_time<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<wkt::Timestamp>,
        {
            self.0.request.departure_time = v.map(|x| x.into());
            self
        }

        /// Sets the value of [arrival_time][crate::model::ComputeRoutesRequest::arrival_time].
        pub fn set_arrival_time<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<wkt::Timestamp>,
        {
            self.0.request.arrival_time = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [arrival_time][crate::model::ComputeRoutesRequest::arrival_time].
        pub fn set_or_clear_arrival_time<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<wkt::Timestamp>,
        {
            self.0.request.arrival_time = v.map(|x| x.into());
            self
        }

        /// Sets the value of [compute_alternative_routes][crate::model::ComputeRoutesRequest::compute_alternative_routes].
        pub fn set_compute_alternative_routes<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.compute_alternative_routes = v.into();
            self
        }

        /// Sets the value of [route_modifiers][crate::model::ComputeRoutesRequest::route_modifiers].
        pub fn set_route_modifiers<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::RouteModifiers>,
        {
            self.0.request.route_modifiers = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [route_modifiers][crate::model::ComputeRoutesRequest::route_modifiers].
        pub fn set_or_clear_route_modifiers<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::RouteModifiers>,
        {
            self.0.request.route_modifiers = v.map(|x| x.into());
            self
        }

        /// Sets the value of [language_code][crate::model::ComputeRoutesRequest::language_code].
        pub fn set_language_code<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.language_code = v.into();
            self
        }

        /// Sets the value of [region_code][crate::model::ComputeRoutesRequest::region_code].
        pub fn set_region_code<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.region_code = v.into();
            self
        }

        /// Sets the value of [units][crate::model::ComputeRoutesRequest::units].
        pub fn set_units<T: Into<crate::model::Units>>(mut self, v: T) -> Self {
            self.0.request.units = v.into();
            self
        }

        /// Sets the value of [optimize_waypoint_order][crate::model::ComputeRoutesRequest::optimize_waypoint_order].
        pub fn set_optimize_waypoint_order<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.optimize_waypoint_order = v.into();
            self
        }

        /// Sets the value of [requested_reference_routes][crate::model::ComputeRoutesRequest::requested_reference_routes].
        pub fn set_requested_reference_routes<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::compute_routes_request::ReferenceRoute>,
        {
            use std::iter::Iterator;
            self.0.request.requested_reference_routes = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [extra_computations][crate::model::ComputeRoutesRequest::extra_computations].
        pub fn set_extra_computations<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::compute_routes_request::ExtraComputation>,
        {
            use std::iter::Iterator;
            self.0.request.extra_computations = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [traffic_model][crate::model::ComputeRoutesRequest::traffic_model].
        pub fn set_traffic_model<T: Into<crate::model::TrafficModel>>(mut self, v: T) -> Self {
            self.0.request.traffic_model = v.into();
            self
        }

        /// Sets the value of [transit_preferences][crate::model::ComputeRoutesRequest::transit_preferences].
        pub fn set_transit_preferences<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::TransitPreferences>,
        {
            self.0.request.transit_preferences = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [transit_preferences][crate::model::ComputeRoutesRequest::transit_preferences].
        pub fn set_or_clear_transit_preferences<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::TransitPreferences>,
        {
            self.0.request.transit_preferences = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for ComputeRoutes {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }
}