google_cloud_location/
builder.rs

1// Copyright 2024 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
17pub mod locations {
18    use crate::Result;
19
20    /// A builder for [Locations][crate::client::Locations].
21    ///
22    /// ```
23    /// # tokio_test::block_on(async {
24    /// # use google_cloud_location::*;
25    /// # use builder::locations::ClientBuilder;
26    /// # use client::Locations;
27    /// let builder : ClientBuilder = Locations::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://cloud.googleapis.com")
30    ///     .build().await?;
31    /// # gax::client_builder::Result::<()>::Ok(()) });
32    /// ```
33    pub type ClientBuilder =
34        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::Locations;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = Locations;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> gax::client_builder::Result<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::Locations] request builders.
52    #[derive(Clone, Debug)]
53    pub(crate) struct RequestBuilder<R: std::default::Default> {
54        stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
55        request: R,
56        options: gax::options::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(
64            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
65        ) -> Self {
66            Self {
67                stub,
68                request: R::default(),
69                options: gax::options::RequestOptions::default(),
70            }
71        }
72    }
73
74    /// The request builder for [Locations::list_locations][crate::client::Locations::list_locations] calls.
75    ///
76    /// # Example
77    /// ```no_run
78    /// # use google_cloud_location::builder;
79    /// use builder::locations::ListLocations;
80    /// # tokio_test::block_on(async {
81    /// use gax::paginator::ItemPaginator;
82    ///
83    /// let builder = prepare_request_builder();
84    /// let mut items = builder.by_item();
85    /// while let Some(result) = items.next().await {
86    ///   let item = result?;
87    /// }
88    /// # gax::Result::<()>::Ok(()) });
89    ///
90    /// fn prepare_request_builder() -> ListLocations {
91    ///   # panic!();
92    ///   // ... details omitted ...
93    /// }
94    /// ```
95    #[derive(Clone, Debug)]
96    pub struct ListLocations(RequestBuilder<crate::model::ListLocationsRequest>);
97
98    impl ListLocations {
99        pub(crate) fn new(
100            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
101        ) -> Self {
102            Self(RequestBuilder::new(stub))
103        }
104
105        /// Sets the full request, replacing any prior values.
106        pub fn with_request<V: Into<crate::model::ListLocationsRequest>>(mut self, v: V) -> Self {
107            self.0.request = v.into();
108            self
109        }
110
111        /// Sets all the options, replacing any prior values.
112        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
113            self.0.options = v.into();
114            self
115        }
116
117        /// Sends the request.
118        pub async fn send(self) -> Result<crate::model::ListLocationsResponse> {
119            (*self.0.stub)
120                .list_locations(self.0.request, self.0.options)
121                .await
122                .map(gax::response::Response::into_body)
123        }
124
125        /// Streams each page in the collection.
126        pub fn by_page(
127            self,
128        ) -> impl gax::paginator::Paginator<crate::model::ListLocationsResponse, gax::error::Error>
129        {
130            use std::clone::Clone;
131            let token = self.0.request.page_token.clone();
132            let execute = move |token: String| {
133                let mut builder = self.clone();
134                builder.0.request = builder.0.request.set_page_token(token);
135                builder.send()
136            };
137            gax::paginator::internal::new_paginator(token, execute)
138        }
139
140        /// Streams each item in the collection.
141        pub fn by_item(
142            self,
143        ) -> impl gax::paginator::ItemPaginator<crate::model::ListLocationsResponse, gax::error::Error>
144        {
145            use gax::paginator::Paginator;
146            self.by_page().items()
147        }
148
149        /// Sets the value of [name][crate::model::ListLocationsRequest::name].
150        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
151            self.0.request.name = v.into();
152            self
153        }
154
155        /// Sets the value of [filter][crate::model::ListLocationsRequest::filter].
156        pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
157            self.0.request.filter = v.into();
158            self
159        }
160
161        /// Sets the value of [page_size][crate::model::ListLocationsRequest::page_size].
162        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
163            self.0.request.page_size = v.into();
164            self
165        }
166
167        /// Sets the value of [page_token][crate::model::ListLocationsRequest::page_token].
168        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
169            self.0.request.page_token = v.into();
170            self
171        }
172    }
173
174    #[doc(hidden)]
175    impl gax::options::internal::RequestBuilder for ListLocations {
176        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
177            &mut self.0.options
178        }
179    }
180
181    /// The request builder for [Locations::get_location][crate::client::Locations::get_location] calls.
182    ///
183    /// # Example
184    /// ```no_run
185    /// # use google_cloud_location::builder;
186    /// use builder::locations::GetLocation;
187    /// # tokio_test::block_on(async {
188    ///
189    /// let builder = prepare_request_builder();
190    /// let response = builder.send().await?;
191    /// # gax::Result::<()>::Ok(()) });
192    ///
193    /// fn prepare_request_builder() -> GetLocation {
194    ///   # panic!();
195    ///   // ... details omitted ...
196    /// }
197    /// ```
198    #[derive(Clone, Debug)]
199    pub struct GetLocation(RequestBuilder<crate::model::GetLocationRequest>);
200
201    impl GetLocation {
202        pub(crate) fn new(
203            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
204        ) -> Self {
205            Self(RequestBuilder::new(stub))
206        }
207
208        /// Sets the full request, replacing any prior values.
209        pub fn with_request<V: Into<crate::model::GetLocationRequest>>(mut self, v: V) -> Self {
210            self.0.request = v.into();
211            self
212        }
213
214        /// Sets all the options, replacing any prior values.
215        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
216            self.0.options = v.into();
217            self
218        }
219
220        /// Sends the request.
221        pub async fn send(self) -> Result<crate::model::Location> {
222            (*self.0.stub)
223                .get_location(self.0.request, self.0.options)
224                .await
225                .map(gax::response::Response::into_body)
226        }
227
228        /// Sets the value of [name][crate::model::GetLocationRequest::name].
229        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
230            self.0.request.name = v.into();
231            self
232        }
233    }
234
235    #[doc(hidden)]
236    impl gax::options::internal::RequestBuilder for GetLocation {
237        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
238            &mut self.0.options
239        }
240    }
241}