Skip to main content

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() -> google_cloud_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 = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;
34
35    pub(crate) mod client {
36        use super::super::super::client::Locations;
37        pub struct Factory;
38        impl crate::ClientFactory for Factory {
39            type Client = Locations;
40            type Credentials = gaxi::options::Credentials;
41            async fn build(
42                self,
43                config: gaxi::options::ClientConfig,
44            ) -> crate::ClientBuilderResult<Self::Client> {
45                Self::Client::new(config).await
46            }
47        }
48    }
49
50    /// Common implementation for [crate::client::Locations] request builders.
51    #[derive(Clone, Debug)]
52    pub(crate) struct RequestBuilder<R: std::default::Default> {
53        stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
54        request: R,
55        options: crate::RequestOptions,
56    }
57
58    impl<R> RequestBuilder<R>
59    where
60        R: std::default::Default,
61    {
62        pub(crate) fn new(
63            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
64        ) -> Self {
65            Self {
66                stub,
67                request: R::default(),
68                options: crate::RequestOptions::default(),
69            }
70        }
71    }
72
73    /// The request builder for [Locations::list_locations][crate::client::Locations::list_locations] calls.
74    ///
75    /// # Example
76    /// ```
77    /// # use google_cloud_location::builder::locations::ListLocations;
78    /// # async fn sample() -> google_cloud_location::Result<()> {
79    /// use google_cloud_gax::paginator::ItemPaginator;
80    ///
81    /// let builder = prepare_request_builder();
82    /// let mut items = builder.by_item();
83    /// while let Some(result) = items.next().await {
84    ///   let item = result?;
85    /// }
86    /// # Ok(()) }
87    ///
88    /// fn prepare_request_builder() -> ListLocations {
89    ///   # panic!();
90    ///   // ... details omitted ...
91    /// }
92    /// ```
93    #[derive(Clone, Debug)]
94    pub struct ListLocations(RequestBuilder<crate::model::ListLocationsRequest>);
95
96    impl ListLocations {
97        pub(crate) fn new(
98            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
99        ) -> Self {
100            Self(RequestBuilder::new(stub))
101        }
102
103        /// Sets the full request, replacing any prior values.
104        pub fn with_request<V: Into<crate::model::ListLocationsRequest>>(mut self, v: V) -> Self {
105            self.0.request = v.into();
106            self
107        }
108
109        /// Sets all the options, replacing any prior values.
110        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
111            self.0.options = v.into();
112            self
113        }
114
115        /// Sends the request.
116        pub async fn send(self) -> Result<crate::model::ListLocationsResponse> {
117            (*self.0.stub)
118                .list_locations(self.0.request, self.0.options)
119                .await
120                .map(crate::Response::into_body)
121        }
122
123        /// Streams each page in the collection.
124        pub fn by_page(
125            self,
126        ) -> impl google_cloud_gax::paginator::Paginator<crate::model::ListLocationsResponse, crate::Error>
127        {
128            use std::clone::Clone;
129            let token = self.0.request.page_token.clone();
130            let execute = move |token: String| {
131                let mut builder = self.clone();
132                builder.0.request = builder.0.request.set_page_token(token);
133                builder.send()
134            };
135            google_cloud_gax::paginator::internal::new_paginator(token, execute)
136        }
137
138        /// Streams each item in the collection.
139        pub fn by_item(
140            self,
141        ) -> impl google_cloud_gax::paginator::ItemPaginator<
142            crate::model::ListLocationsResponse,
143            crate::Error,
144        > {
145            use google_cloud_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 crate::RequestBuilder for ListLocations {
176        fn request_options(&mut self) -> &mut crate::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    /// ```
185    /// # use google_cloud_location::builder::locations::GetLocation;
186    /// # async fn sample() -> google_cloud_location::Result<()> {
187    ///
188    /// let builder = prepare_request_builder();
189    /// let response = builder.send().await?;
190    /// # Ok(()) }
191    ///
192    /// fn prepare_request_builder() -> GetLocation {
193    ///   # panic!();
194    ///   // ... details omitted ...
195    /// }
196    /// ```
197    #[derive(Clone, Debug)]
198    pub struct GetLocation(RequestBuilder<crate::model::GetLocationRequest>);
199
200    impl GetLocation {
201        pub(crate) fn new(
202            stub: std::sync::Arc<dyn super::super::stub::dynamic::Locations>,
203        ) -> Self {
204            Self(RequestBuilder::new(stub))
205        }
206
207        /// Sets the full request, replacing any prior values.
208        pub fn with_request<V: Into<crate::model::GetLocationRequest>>(mut self, v: V) -> Self {
209            self.0.request = v.into();
210            self
211        }
212
213        /// Sets all the options, replacing any prior values.
214        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
215            self.0.options = v.into();
216            self
217        }
218
219        /// Sends the request.
220        pub async fn send(self) -> Result<crate::model::Location> {
221            (*self.0.stub)
222                .get_location(self.0.request, self.0.options)
223                .await
224                .map(crate::Response::into_body)
225        }
226
227        /// Sets the value of [name][crate::model::GetLocationRequest::name].
228        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
229            self.0.request.name = v.into();
230            self
231        }
232    }
233
234    #[doc(hidden)]
235    impl crate::RequestBuilder for GetLocation {
236        fn request_options(&mut self) -> &mut crate::RequestOptions {
237            &mut self.0.options
238        }
239    }
240}