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
17/// Request and client builders for [Locations][crate::client::Locations].
18pub mod locations {
19 use crate::Result;
20
21 /// A builder for [Locations][crate::client::Locations].
22 ///
23 /// ```
24 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
25 /// # use google_cloud_location::*;
26 /// # use builder::locations::ClientBuilder;
27 /// # use client::Locations;
28 /// let builder : ClientBuilder = Locations::builder();
29 /// let client = builder
30 /// .with_endpoint("https://cloud.googleapis.com")
31 /// .build().await?;
32 /// # Ok(()) }
33 /// ```
34 pub type ClientBuilder = crate::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 crate::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 ) -> crate::ClientBuilderResult<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: crate::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: crate::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() -> google_cloud_location::Result<()> {
80 /// use google_cloud_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<crate::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(crate::Response::into_body)
122 }
123
124 /// Streams each page in the collection.
125 pub fn by_page(
126 self,
127 ) -> impl google_cloud_gax::paginator::Paginator<crate::model::ListLocationsResponse, crate::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 google_cloud_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 google_cloud_gax::paginator::ItemPaginator<
143 crate::model::ListLocationsResponse,
144 crate::Error,
145 > {
146 use google_cloud_gax::paginator::Paginator;
147 self.by_page().items()
148 }
149
150 /// Sets the value of [name][crate::model::ListLocationsRequest::name].
151 pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
152 self.0.request.name = v.into();
153 self
154 }
155
156 /// Sets the value of [filter][crate::model::ListLocationsRequest::filter].
157 pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
158 self.0.request.filter = v.into();
159 self
160 }
161
162 /// Sets the value of [page_size][crate::model::ListLocationsRequest::page_size].
163 pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
164 self.0.request.page_size = v.into();
165 self
166 }
167
168 /// Sets the value of [page_token][crate::model::ListLocationsRequest::page_token].
169 pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
170 self.0.request.page_token = v.into();
171 self
172 }
173 }
174
175 #[doc(hidden)]
176 impl crate::RequestBuilder for ListLocations {
177 fn request_options(&mut self) -> &mut crate::RequestOptions {
178 &mut self.0.options
179 }
180 }
181
182 /// The request builder for [Locations::get_location][crate::client::Locations::get_location] calls.
183 ///
184 /// # Example
185 /// ```
186 /// # use google_cloud_location::builder::locations::GetLocation;
187 /// # async fn sample() -> google_cloud_location::Result<()> {
188 ///
189 /// let builder = prepare_request_builder();
190 /// let response = builder.send().await?;
191 /// # 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<crate::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(crate::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 crate::RequestBuilder for GetLocation {
237 fn request_options(&mut self) -> &mut crate::RequestOptions {
238 &mut self.0.options
239 }
240 }
241}