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