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.

#[allow(unused_imports)]
use crate::Error;
use crate::Result;

/// Implements [Routes](super::stub::Routes) using a [gaxi::http::ReqwestClient].
#[derive(Clone)]
pub struct Routes {
    inner: gaxi::http::ReqwestClient,
}

impl std::fmt::Debug for Routes {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
        f.debug_struct("Routes")
            .field("inner", &self.inner)
            .finish()
    }
}

impl Routes {
    pub async fn new(config: gaxi::options::ClientConfig) -> crate::ClientBuilderResult<Self> {
        let tracing_is_enabled = gaxi::options::tracing_enabled(&config);
        let inner = gaxi::http::ReqwestClient::new(config, crate::DEFAULT_HOST).await?;
        let inner = if tracing_is_enabled {
            inner.with_instrumentation(&super::tracing::info::INSTRUMENTATION_CLIENT_INFO)
        } else {
            inner
        };
        Ok(Self { inner })
    }
}

impl super::stub::Routes for Routes {
    async fn compute_routes(
        &self,
        req: crate::model::ComputeRoutesRequest,
        options: crate::RequestOptions,
    ) -> Result<crate::Response<crate::model::ComputeRoutesResponse>> {
        use gaxi::http::reqwest::{HeaderValue, Method};
        use gaxi::path_parameter::PathMismatchBuilder;
        use google_cloud_gax::error::binding::BindingError;
        let (builder, method, _path_template) = None
            .or_else(|| {
                let path = "/directions/v2:computeRoutes".to_string();
                let path_template = "/directions/v2:computeRoutes";

                let builder = self.inner.builder(Method::POST, path);
                let builder = Ok(builder);
                Some(builder.map(|b| (b, Method::POST, path_template)))
            })
            .ok_or_else(|| {
                let mut paths = Vec::new();
                {
                    let builder = PathMismatchBuilder::default();
                    paths.push(builder.build());
                }
                google_cloud_gax::error::Error::binding(BindingError { paths })
            })??;
        if let Some(recorder) = gaxi::observability::RequestRecorder::current() {
            recorder.on_client_request(
                gaxi::observability::ClientRequestAttributes::default()
                    .set_rpc_method("google.maps.routing.v2.Routes/ComputeRoutes")
                    .set_url_template(_path_template),
            );
        }
        let options = google_cloud_gax::options::internal::set_default_idempotency(
            options,
            gaxi::http::default_idempotency(&method),
        );
        let builder = builder.query(&[("$alt", "json;enum-encoding=int")]).header(
            "x-goog-api-client",
            HeaderValue::from_static(&crate::info::X_GOOG_API_CLIENT_HEADER),
        );
        let body = gaxi::http::handle_empty(Some(req), &method);
        self.inner.execute(builder, body, options).await
    }
}