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    /// # async fn sample() -> gax::client_builder::Result<()> {
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    /// # 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    /// ```
78    /// # use google_cloud_location::builder::locations::ListLocations;
79    /// # async fn sample() -> gax::Result<()> {
80    /// use gax::paginator::ItemPaginator;
81    ///
82    /// let builder = prepare_request_builder();
83    /// let mut items = builder.by_item();
84    /// while let Some(result) = items.next().await {
85    ///   let item = result?;
86    /// }
87    /// # Ok(()) }
88    ///
89    /// fn prepare_request_builder() -> ListLocations {
90    ///   # panic!();
91    ///   // ... details omitted ...
92    /// }
93    /// ```
94    #[derive(Clone, Debug)]
95    pub struct ListLocations(RequestBuilder<crate::model::ListLocationsRequest>);
96
97    impl ListLocations {
98        pub(crate) fn new(
99            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
100        ) -> Self {
101            Self(RequestBuilder::new(stub))
102        }
103
104        /// Sets the full request, replacing any prior values.
105        pub fn with_request<V: Into<crate::model::ListLocationsRequest>>(mut self, v: V) -> Self {
106            self.0.request = v.into();
107            self
108        }
109
110        /// Sets all the options, replacing any prior values.
111        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
112            self.0.options = v.into();
113            self
114        }
115
116        /// Sends the request.
117        pub async fn send(self) -> Result<crate::model::ListLocationsResponse> {
118            (*self.0.stub)
119                .list_locations(self.0.request, self.0.options)
120                .await
121                .map(gax::response::Response::into_body)
122        }
123
124        /// Streams each page in the collection.
125        pub fn by_page(
126            self,
127        ) -> impl gax::paginator::Paginator<crate::model::ListLocationsResponse, gax::error::Error>
128        {
129            use std::clone::Clone;
130            let token = self.0.request.page_token.clone();
131            let execute = move |token: String| {
132                let mut builder = self.clone();
133                builder.0.request = builder.0.request.set_page_token(token);
134                builder.send()
135            };
136            gax::paginator::internal::new_paginator(token, execute)
137        }
138
139        /// Streams each item in the collection.
140        pub fn by_item(
141            self,
142        ) -> impl gax::paginator::ItemPaginator<crate::model::ListLocationsResponse, gax::error::Error>
143        {
144            use gax::paginator::Paginator;
145            self.by_page().items()
146        }
147
148        /// Sets the value of [name][crate::model::ListLocationsRequest::name].
149        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
150            self.0.request.name = v.into();
151            self
152        }
153
154        /// Sets the value of [filter][crate::model::ListLocationsRequest::filter].
155        pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
156            self.0.request.filter = v.into();
157            self
158        }
159
160        /// Sets the value of [page_size][crate::model::ListLocationsRequest::page_size].
161        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
162            self.0.request.page_size = v.into();
163            self
164        }
165
166        /// Sets the value of [page_token][crate::model::ListLocationsRequest::page_token].
167        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
168            self.0.request.page_token = v.into();
169            self
170        }
171    }
172
173    #[doc(hidden)]
174    impl gax::options::internal::RequestBuilder for ListLocations {
175        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
176            &mut self.0.options
177        }
178    }
179
180    /// The request builder for [Locations::get_location][crate::client::Locations::get_location] calls.
181    ///
182    /// # Example
183    /// ```
184    /// # use google_cloud_location::builder::locations::GetLocation;
185    /// # async fn sample() -> gax::Result<()> {
186    ///
187    /// let builder = prepare_request_builder();
188    /// let response = builder.send().await?;
189    /// # Ok(()) }
190    ///
191    /// fn prepare_request_builder() -> GetLocation {
192    ///   # panic!();
193    ///   // ... details omitted ...
194    /// }
195    /// ```
196    #[derive(Clone, Debug)]
197    pub struct GetLocation(RequestBuilder<crate::model::GetLocationRequest>);
198
199    impl GetLocation {
200        pub(crate) fn new(
201            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
202        ) -> Self {
203            Self(RequestBuilder::new(stub))
204        }
205
206        /// Sets the full request, replacing any prior values.
207        pub fn with_request<V: Into<crate::model::GetLocationRequest>>(mut self, v: V) -> Self {
208            self.0.request = v.into();
209            self
210        }
211
212        /// Sets all the options, replacing any prior values.
213        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
214            self.0.options = v.into();
215            self
216        }
217
218        /// Sends the request.
219        pub async fn send(self) -> Result<crate::model::Location> {
220            (*self.0.stub)
221                .get_location(self.0.request, self.0.options)
222                .await
223                .map(gax::response::Response::into_body)
224        }
225
226        /// Sets the value of [name][crate::model::GetLocationRequest::name].
227        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
228            self.0.request.name = v.into();
229            self
230        }
231    }
232
233    #[doc(hidden)]
234    impl gax::options::internal::RequestBuilder for GetLocation {
235        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
236            &mut self.0.options
237        }
238    }
239}