Skip to main content

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