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][crate::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::client_builder::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(
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::LanguageService] 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::LanguageService>,
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::LanguageService>,
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 [LanguageService::analyze_sentiment][crate::client::LanguageService::analyze_sentiment] calls.
75 ///
76 /// # Example
77 /// ```no_run
78 /// # use google_cloud_language_v2::builder;
79 /// use builder::language_service::AnalyzeSentiment;
80 /// # tokio_test::block_on(async {
81 ///
82 /// let builder = prepare_request_builder();
83 /// let response = builder.send().await?;
84 /// # gax::Result::<()>::Ok(()) });
85 ///
86 /// fn prepare_request_builder() -> AnalyzeSentiment {
87 /// # panic!();
88 /// // ... details omitted ...
89 /// }
90 /// ```
91 #[derive(Clone, Debug)]
92 pub struct AnalyzeSentiment(RequestBuilder<crate::model::AnalyzeSentimentRequest>);
93
94 impl AnalyzeSentiment {
95 pub(crate) fn new(
96 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
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::AnalyzeSentimentRequest>>(
103 mut self,
104 v: V,
105 ) -> 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::AnalyzeSentimentResponse> {
118 (*self.0.stub)
119 .analyze_sentiment(self.0.request, self.0.options)
120 .await
121 .map(gax::response::Response::into_body)
122 }
123
124 /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
125 ///
126 /// This is a **required** field for requests.
127 pub fn set_document<T>(mut self, v: T) -> Self
128 where
129 T: std::convert::Into<crate::model::Document>,
130 {
131 self.0.request.document = std::option::Option::Some(v.into());
132 self
133 }
134
135 /// Sets or clears the value of [document][crate::model::AnalyzeSentimentRequest::document].
136 ///
137 /// This is a **required** field for requests.
138 pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
139 where
140 T: std::convert::Into<crate::model::Document>,
141 {
142 self.0.request.document = v.map(|x| x.into());
143 self
144 }
145
146 /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
147 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
148 self.0.request.encoding_type = v.into();
149 self
150 }
151 }
152
153 #[doc(hidden)]
154 impl gax::options::internal::RequestBuilder for AnalyzeSentiment {
155 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
156 &mut self.0.options
157 }
158 }
159
160 /// The request builder for [LanguageService::analyze_entities][crate::client::LanguageService::analyze_entities] calls.
161 ///
162 /// # Example
163 /// ```no_run
164 /// # use google_cloud_language_v2::builder;
165 /// use builder::language_service::AnalyzeEntities;
166 /// # tokio_test::block_on(async {
167 ///
168 /// let builder = prepare_request_builder();
169 /// let response = builder.send().await?;
170 /// # gax::Result::<()>::Ok(()) });
171 ///
172 /// fn prepare_request_builder() -> AnalyzeEntities {
173 /// # panic!();
174 /// // ... details omitted ...
175 /// }
176 /// ```
177 #[derive(Clone, Debug)]
178 pub struct AnalyzeEntities(RequestBuilder<crate::model::AnalyzeEntitiesRequest>);
179
180 impl AnalyzeEntities {
181 pub(crate) fn new(
182 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
183 ) -> Self {
184 Self(RequestBuilder::new(stub))
185 }
186
187 /// Sets the full request, replacing any prior values.
188 pub fn with_request<V: Into<crate::model::AnalyzeEntitiesRequest>>(mut self, v: V) -> Self {
189 self.0.request = v.into();
190 self
191 }
192
193 /// Sets all the options, replacing any prior values.
194 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
195 self.0.options = v.into();
196 self
197 }
198
199 /// Sends the request.
200 pub async fn send(self) -> Result<crate::model::AnalyzeEntitiesResponse> {
201 (*self.0.stub)
202 .analyze_entities(self.0.request, self.0.options)
203 .await
204 .map(gax::response::Response::into_body)
205 }
206
207 /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
208 ///
209 /// This is a **required** field for requests.
210 pub fn set_document<T>(mut self, v: T) -> Self
211 where
212 T: std::convert::Into<crate::model::Document>,
213 {
214 self.0.request.document = std::option::Option::Some(v.into());
215 self
216 }
217
218 /// Sets or clears the value of [document][crate::model::AnalyzeEntitiesRequest::document].
219 ///
220 /// This is a **required** field for requests.
221 pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
222 where
223 T: std::convert::Into<crate::model::Document>,
224 {
225 self.0.request.document = v.map(|x| x.into());
226 self
227 }
228
229 /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
230 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
231 self.0.request.encoding_type = v.into();
232 self
233 }
234 }
235
236 #[doc(hidden)]
237 impl gax::options::internal::RequestBuilder for AnalyzeEntities {
238 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
239 &mut self.0.options
240 }
241 }
242
243 /// The request builder for [LanguageService::classify_text][crate::client::LanguageService::classify_text] calls.
244 ///
245 /// # Example
246 /// ```no_run
247 /// # use google_cloud_language_v2::builder;
248 /// use builder::language_service::ClassifyText;
249 /// # tokio_test::block_on(async {
250 ///
251 /// let builder = prepare_request_builder();
252 /// let response = builder.send().await?;
253 /// # gax::Result::<()>::Ok(()) });
254 ///
255 /// fn prepare_request_builder() -> ClassifyText {
256 /// # panic!();
257 /// // ... details omitted ...
258 /// }
259 /// ```
260 #[derive(Clone, Debug)]
261 pub struct ClassifyText(RequestBuilder<crate::model::ClassifyTextRequest>);
262
263 impl ClassifyText {
264 pub(crate) fn new(
265 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
266 ) -> Self {
267 Self(RequestBuilder::new(stub))
268 }
269
270 /// Sets the full request, replacing any prior values.
271 pub fn with_request<V: Into<crate::model::ClassifyTextRequest>>(mut self, v: V) -> Self {
272 self.0.request = v.into();
273 self
274 }
275
276 /// Sets all the options, replacing any prior values.
277 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
278 self.0.options = v.into();
279 self
280 }
281
282 /// Sends the request.
283 pub async fn send(self) -> Result<crate::model::ClassifyTextResponse> {
284 (*self.0.stub)
285 .classify_text(self.0.request, self.0.options)
286 .await
287 .map(gax::response::Response::into_body)
288 }
289
290 /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
291 ///
292 /// This is a **required** field for requests.
293 pub fn set_document<T>(mut self, v: T) -> Self
294 where
295 T: std::convert::Into<crate::model::Document>,
296 {
297 self.0.request.document = std::option::Option::Some(v.into());
298 self
299 }
300
301 /// Sets or clears the value of [document][crate::model::ClassifyTextRequest::document].
302 ///
303 /// This is a **required** field for requests.
304 pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
305 where
306 T: std::convert::Into<crate::model::Document>,
307 {
308 self.0.request.document = v.map(|x| x.into());
309 self
310 }
311 }
312
313 #[doc(hidden)]
314 impl gax::options::internal::RequestBuilder for ClassifyText {
315 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
316 &mut self.0.options
317 }
318 }
319
320 /// The request builder for [LanguageService::moderate_text][crate::client::LanguageService::moderate_text] calls.
321 ///
322 /// # Example
323 /// ```no_run
324 /// # use google_cloud_language_v2::builder;
325 /// use builder::language_service::ModerateText;
326 /// # tokio_test::block_on(async {
327 ///
328 /// let builder = prepare_request_builder();
329 /// let response = builder.send().await?;
330 /// # gax::Result::<()>::Ok(()) });
331 ///
332 /// fn prepare_request_builder() -> ModerateText {
333 /// # panic!();
334 /// // ... details omitted ...
335 /// }
336 /// ```
337 #[derive(Clone, Debug)]
338 pub struct ModerateText(RequestBuilder<crate::model::ModerateTextRequest>);
339
340 impl ModerateText {
341 pub(crate) fn new(
342 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
343 ) -> Self {
344 Self(RequestBuilder::new(stub))
345 }
346
347 /// Sets the full request, replacing any prior values.
348 pub fn with_request<V: Into<crate::model::ModerateTextRequest>>(mut self, v: V) -> Self {
349 self.0.request = v.into();
350 self
351 }
352
353 /// Sets all the options, replacing any prior values.
354 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
355 self.0.options = v.into();
356 self
357 }
358
359 /// Sends the request.
360 pub async fn send(self) -> Result<crate::model::ModerateTextResponse> {
361 (*self.0.stub)
362 .moderate_text(self.0.request, self.0.options)
363 .await
364 .map(gax::response::Response::into_body)
365 }
366
367 /// Sets the value of [document][crate::model::ModerateTextRequest::document].
368 ///
369 /// This is a **required** field for requests.
370 pub fn set_document<T>(mut self, v: T) -> Self
371 where
372 T: std::convert::Into<crate::model::Document>,
373 {
374 self.0.request.document = std::option::Option::Some(v.into());
375 self
376 }
377
378 /// Sets or clears the value of [document][crate::model::ModerateTextRequest::document].
379 ///
380 /// This is a **required** field for requests.
381 pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
382 where
383 T: std::convert::Into<crate::model::Document>,
384 {
385 self.0.request.document = v.map(|x| x.into());
386 self
387 }
388
389 /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
390 pub fn set_model_version<T: Into<crate::model::moderate_text_request::ModelVersion>>(
391 mut self,
392 v: T,
393 ) -> Self {
394 self.0.request.model_version = v.into();
395 self
396 }
397 }
398
399 #[doc(hidden)]
400 impl gax::options::internal::RequestBuilder for ModerateText {
401 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
402 &mut self.0.options
403 }
404 }
405
406 /// The request builder for [LanguageService::annotate_text][crate::client::LanguageService::annotate_text] calls.
407 ///
408 /// # Example
409 /// ```no_run
410 /// # use google_cloud_language_v2::builder;
411 /// use builder::language_service::AnnotateText;
412 /// # tokio_test::block_on(async {
413 ///
414 /// let builder = prepare_request_builder();
415 /// let response = builder.send().await?;
416 /// # gax::Result::<()>::Ok(()) });
417 ///
418 /// fn prepare_request_builder() -> AnnotateText {
419 /// # panic!();
420 /// // ... details omitted ...
421 /// }
422 /// ```
423 #[derive(Clone, Debug)]
424 pub struct AnnotateText(RequestBuilder<crate::model::AnnotateTextRequest>);
425
426 impl AnnotateText {
427 pub(crate) fn new(
428 stub: std::sync::Arc<dyn super::super::stub::dynamic::LanguageService>,
429 ) -> Self {
430 Self(RequestBuilder::new(stub))
431 }
432
433 /// Sets the full request, replacing any prior values.
434 pub fn with_request<V: Into<crate::model::AnnotateTextRequest>>(mut self, v: V) -> Self {
435 self.0.request = v.into();
436 self
437 }
438
439 /// Sets all the options, replacing any prior values.
440 pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
441 self.0.options = v.into();
442 self
443 }
444
445 /// Sends the request.
446 pub async fn send(self) -> Result<crate::model::AnnotateTextResponse> {
447 (*self.0.stub)
448 .annotate_text(self.0.request, self.0.options)
449 .await
450 .map(gax::response::Response::into_body)
451 }
452
453 /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
454 ///
455 /// This is a **required** field for requests.
456 pub fn set_document<T>(mut self, v: T) -> Self
457 where
458 T: std::convert::Into<crate::model::Document>,
459 {
460 self.0.request.document = std::option::Option::Some(v.into());
461 self
462 }
463
464 /// Sets or clears the value of [document][crate::model::AnnotateTextRequest::document].
465 ///
466 /// This is a **required** field for requests.
467 pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
468 where
469 T: std::convert::Into<crate::model::Document>,
470 {
471 self.0.request.document = v.map(|x| x.into());
472 self
473 }
474
475 /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
476 ///
477 /// This is a **required** field for requests.
478 pub fn set_features<T>(mut self, v: T) -> Self
479 where
480 T: std::convert::Into<crate::model::annotate_text_request::Features>,
481 {
482 self.0.request.features = std::option::Option::Some(v.into());
483 self
484 }
485
486 /// Sets or clears the value of [features][crate::model::AnnotateTextRequest::features].
487 ///
488 /// This is a **required** field for requests.
489 pub fn set_or_clear_features<T>(mut self, v: std::option::Option<T>) -> Self
490 where
491 T: std::convert::Into<crate::model::annotate_text_request::Features>,
492 {
493 self.0.request.features = v.map(|x| x.into());
494 self
495 }
496
497 /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
498 pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
499 self.0.request.encoding_type = v.into();
500 self
501 }
502 }
503
504 #[doc(hidden)]
505 impl gax::options::internal::RequestBuilder for AnnotateText {
506 fn request_options(&mut self) -> &mut gax::options::RequestOptions {
507 &mut self.0.options
508 }
509 }
510}