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