google_cloud_language_v2/builder.rs
1// Copyright 2025 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 language_service {
18 use crate::Result;
19
20 /// A builder for [LanguageService][super::super::client::LanguageService].
21 ///
22 /// ```
23 /// # tokio_test::block_on(async {
24 /// # use google_cloud_language_v2::*;
25 /// # use builder::language_service::ClientBuilder;
26 /// # use client::LanguageService;
27 /// let builder : ClientBuilder = LanguageService::builder();
28 /// let client = builder
29 /// .with_endpoint("https://language.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::LanguageService;
38 pub struct Factory;
39 impl gax::client_builder::internal::ClientFactory for Factory {
40 type Client = LanguageService;
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::LanguageService] 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::LanguageService>,
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::LanguageService>,
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 [LanguageService::analyze_sentiment][super::super::client::LanguageService::analyze_sentiment] calls.
72 ///
73 /// # Example
74 /// ```no_run
75 /// # use google_cloud_language_v2::builder;
76 /// use builder::language_service::AnalyzeSentiment;
77 /// # tokio_test::block_on(async {
78 /// let builder = prepare_request_builder();
79 /// let response = builder.send().await?;
80 /// # gax::Result::<()>::Ok(()) });
81 ///
82 /// fn prepare_request_builder() -> AnalyzeSentiment {
83 /// # panic!();
84 /// // ... details omitted ...
85 /// }
86 /// ```
87 #[derive(Clone, Debug)]
88 pub struct AnalyzeSentiment(RequestBuilder<crate::model::AnalyzeSentimentRequest>);
89
90 impl AnalyzeSentiment {
91 pub(crate) fn new(
92 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
93 ) -> Self {
94 Self(RequestBuilder::new(stub))
95 }
96
97 /// Sets the full request, replacing any prior values.
98 pub fn with_request<V: Into<crate::model::AnalyzeSentimentRequest>>(
99 mut self,
100 v: V,
101 ) -> Self {
102 self.0.request = v.into();
103 self
104 }
105
106 /// Sets all the options, replacing any prior values.
107 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
108 self.0.options = v.into();
109 self
110 }
111
112 /// Sends the request.
113 pub async fn send(self) -> Result<crate::model::AnalyzeSentimentResponse> {
114 (*self.0.stub)
115 .analyze_sentiment(self.0.request, self.0.options)
116 .await
117 .map(gax::response::Response::into_body)
118 }
119
120 /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
121 ///
122 /// This is a **required** field for requests.
123 pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
124 mut self,
125 v: T,
126 ) -> Self {
127 self.0.request.document = v.into();
128 self
129 }
130
131 /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
132 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
133 self.0.request.encoding_type = v.into();
134 self
135 }
136 }
137
138 #[doc(hidden)]
139 impl gax::options::internal::RequestBuilder for AnalyzeSentiment {
140 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
141 &mut self.0.options
142 }
143 }
144
145 /// The request builder for [LanguageService::analyze_entities][super::super::client::LanguageService::analyze_entities] calls.
146 ///
147 /// # Example
148 /// ```no_run
149 /// # use google_cloud_language_v2::builder;
150 /// use builder::language_service::AnalyzeEntities;
151 /// # tokio_test::block_on(async {
152 /// let builder = prepare_request_builder();
153 /// let response = builder.send().await?;
154 /// # gax::Result::<()>::Ok(()) });
155 ///
156 /// fn prepare_request_builder() -> AnalyzeEntities {
157 /// # panic!();
158 /// // ... details omitted ...
159 /// }
160 /// ```
161 #[derive(Clone, Debug)]
162 pub struct AnalyzeEntities(RequestBuilder<crate::model::AnalyzeEntitiesRequest>);
163
164 impl AnalyzeEntities {
165 pub(crate) fn new(
166 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
167 ) -> Self {
168 Self(RequestBuilder::new(stub))
169 }
170
171 /// Sets the full request, replacing any prior values.
172 pub fn with_request<V: Into<crate::model::AnalyzeEntitiesRequest>>(mut self, v: V) -> Self {
173 self.0.request = v.into();
174 self
175 }
176
177 /// Sets all the options, replacing any prior values.
178 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
179 self.0.options = v.into();
180 self
181 }
182
183 /// Sends the request.
184 pub async fn send(self) -> Result<crate::model::AnalyzeEntitiesResponse> {
185 (*self.0.stub)
186 .analyze_entities(self.0.request, self.0.options)
187 .await
188 .map(gax::response::Response::into_body)
189 }
190
191 /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
192 ///
193 /// This is a **required** field for requests.
194 pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
195 mut self,
196 v: T,
197 ) -> Self {
198 self.0.request.document = v.into();
199 self
200 }
201
202 /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
203 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
204 self.0.request.encoding_type = v.into();
205 self
206 }
207 }
208
209 #[doc(hidden)]
210 impl gax::options::internal::RequestBuilder for AnalyzeEntities {
211 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
212 &mut self.0.options
213 }
214 }
215
216 /// The request builder for [LanguageService::classify_text][super::super::client::LanguageService::classify_text] calls.
217 ///
218 /// # Example
219 /// ```no_run
220 /// # use google_cloud_language_v2::builder;
221 /// use builder::language_service::ClassifyText;
222 /// # tokio_test::block_on(async {
223 /// let builder = prepare_request_builder();
224 /// let response = builder.send().await?;
225 /// # gax::Result::<()>::Ok(()) });
226 ///
227 /// fn prepare_request_builder() -> ClassifyText {
228 /// # panic!();
229 /// // ... details omitted ...
230 /// }
231 /// ```
232 #[derive(Clone, Debug)]
233 pub struct ClassifyText(RequestBuilder<crate::model::ClassifyTextRequest>);
234
235 impl ClassifyText {
236 pub(crate) fn new(
237 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
238 ) -> Self {
239 Self(RequestBuilder::new(stub))
240 }
241
242 /// Sets the full request, replacing any prior values.
243 pub fn with_request<V: Into<crate::model::ClassifyTextRequest>>(mut self, v: V) -> Self {
244 self.0.request = v.into();
245 self
246 }
247
248 /// Sets all the options, replacing any prior values.
249 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
250 self.0.options = v.into();
251 self
252 }
253
254 /// Sends the request.
255 pub async fn send(self) -> Result<crate::model::ClassifyTextResponse> {
256 (*self.0.stub)
257 .classify_text(self.0.request, self.0.options)
258 .await
259 .map(gax::response::Response::into_body)
260 }
261
262 /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
263 ///
264 /// This is a **required** field for requests.
265 pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
266 mut self,
267 v: T,
268 ) -> Self {
269 self.0.request.document = v.into();
270 self
271 }
272 }
273
274 #[doc(hidden)]
275 impl gax::options::internal::RequestBuilder for ClassifyText {
276 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
277 &mut self.0.options
278 }
279 }
280
281 /// The request builder for [LanguageService::moderate_text][super::super::client::LanguageService::moderate_text] calls.
282 ///
283 /// # Example
284 /// ```no_run
285 /// # use google_cloud_language_v2::builder;
286 /// use builder::language_service::ModerateText;
287 /// # tokio_test::block_on(async {
288 /// let builder = prepare_request_builder();
289 /// let response = builder.send().await?;
290 /// # gax::Result::<()>::Ok(()) });
291 ///
292 /// fn prepare_request_builder() -> ModerateText {
293 /// # panic!();
294 /// // ... details omitted ...
295 /// }
296 /// ```
297 #[derive(Clone, Debug)]
298 pub struct ModerateText(RequestBuilder<crate::model::ModerateTextRequest>);
299
300 impl ModerateText {
301 pub(crate) fn new(
302 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
303 ) -> Self {
304 Self(RequestBuilder::new(stub))
305 }
306
307 /// Sets the full request, replacing any prior values.
308 pub fn with_request<V: Into<crate::model::ModerateTextRequest>>(mut self, v: V) -> Self {
309 self.0.request = v.into();
310 self
311 }
312
313 /// Sets all the options, replacing any prior values.
314 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
315 self.0.options = v.into();
316 self
317 }
318
319 /// Sends the request.
320 pub async fn send(self) -> Result<crate::model::ModerateTextResponse> {
321 (*self.0.stub)
322 .moderate_text(self.0.request, self.0.options)
323 .await
324 .map(gax::response::Response::into_body)
325 }
326
327 /// Sets the value of [document][crate::model::ModerateTextRequest::document].
328 ///
329 /// This is a **required** field for requests.
330 pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
331 mut self,
332 v: T,
333 ) -> Self {
334 self.0.request.document = v.into();
335 self
336 }
337
338 /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
339 pub fn set_model_version<T: Into<crate::model::moderate_text_request::ModelVersion>>(
340 mut self,
341 v: T,
342 ) -> Self {
343 self.0.request.model_version = v.into();
344 self
345 }
346 }
347
348 #[doc(hidden)]
349 impl gax::options::internal::RequestBuilder for ModerateText {
350 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
351 &mut self.0.options
352 }
353 }
354
355 /// The request builder for [LanguageService::annotate_text][super::super::client::LanguageService::annotate_text] calls.
356 ///
357 /// # Example
358 /// ```no_run
359 /// # use google_cloud_language_v2::builder;
360 /// use builder::language_service::AnnotateText;
361 /// # tokio_test::block_on(async {
362 /// let builder = prepare_request_builder();
363 /// let response = builder.send().await?;
364 /// # gax::Result::<()>::Ok(()) });
365 ///
366 /// fn prepare_request_builder() -> AnnotateText {
367 /// # panic!();
368 /// // ... details omitted ...
369 /// }
370 /// ```
371 #[derive(Clone, Debug)]
372 pub struct AnnotateText(RequestBuilder<crate::model::AnnotateTextRequest>);
373
374 impl AnnotateText {
375 pub(crate) fn new(
376 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
377 ) -> Self {
378 Self(RequestBuilder::new(stub))
379 }
380
381 /// Sets the full request, replacing any prior values.
382 pub fn with_request<V: Into<crate::model::AnnotateTextRequest>>(mut self, v: V) -> Self {
383 self.0.request = v.into();
384 self
385 }
386
387 /// Sets all the options, replacing any prior values.
388 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
389 self.0.options = v.into();
390 self
391 }
392
393 /// Sends the request.
394 pub async fn send(self) -> Result<crate::model::AnnotateTextResponse> {
395 (*self.0.stub)
396 .annotate_text(self.0.request, self.0.options)
397 .await
398 .map(gax::response::Response::into_body)
399 }
400
401 /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
402 ///
403 /// This is a **required** field for requests.
404 pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
405 mut self,
406 v: T,
407 ) -> Self {
408 self.0.request.document = v.into();
409 self
410 }
411
412 /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
413 ///
414 /// This is a **required** field for requests.
415 pub fn set_features<
416 T: Into<std::option::Option<crate::model::annotate_text_request::Features>>,
417 >(
418 mut self,
419 v: T,
420 ) -> Self {
421 self.0.request.features = v.into();
422 self
423 }
424
425 /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
426 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
427 self.0.request.encoding_type = v.into();
428 self
429 }
430 }
431
432 #[doc(hidden)]
433 impl gax::options::internal::RequestBuilder for AnnotateText {
434 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
435 &mut self.0.options
436 }
437 }
438}