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    use std::sync::Arc;
20
21    /// A builder for [LanguageService][super::super::client::LanguageService].
22    ///
23    /// ```
24    /// # tokio_test::block_on(async {
25    /// # use google_cloud_language_v2::*;
26    /// # use builder::language_service::ClientBuilder;
27    /// # use client::LanguageService;
28    /// let builder : ClientBuilder = LanguageService::builder();
29    /// let client = builder
30    ///     .with_endpoint("https://language.googleapis.com")
31    ///     .build().await?;
32    /// # gax::Result::<()>::Ok(()) });
33    /// ```
34    pub type ClientBuilder =
35        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
36
37    pub(crate) mod client {
38        use super::super::super::client::LanguageService;
39        pub struct Factory;
40        impl gax::client_builder::internal::ClientFactory for Factory {
41            type Client = LanguageService;
42            type Credentials = gaxi::options::Credentials;
43            async fn build(self, config: gaxi::options::ClientConfig) -> gax::Result<Self::Client> {
44                Self::Client::new(config).await
45            }
46        }
47    }
48
49    /// Common implementation for [super::super::client::LanguageService] request builders.
50    #[derive(Clone, Debug)]
51    pub(crate) struct RequestBuilder<R: std::default::Default> {
52        stub: Arc<dyn super::super::stub::dynamic::LanguageService>,
53        request: R,
54        options: gax::options::RequestOptions,
55    }
56
57    impl<R> RequestBuilder<R>
58    where
59        R: std::default::Default,
60    {
61        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
62            Self {
63                stub,
64                request: R::default(),
65                options: gax::options::RequestOptions::default(),
66            }
67        }
68    }
69
70    /// The request builder for [LanguageService::analyze_sentiment][super::super::client::LanguageService::analyze_sentiment] calls.
71    #[derive(Clone, Debug)]
72    pub struct AnalyzeSentiment(RequestBuilder<crate::model::AnalyzeSentimentRequest>);
73
74    impl AnalyzeSentiment {
75        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
76            Self(RequestBuilder::new(stub))
77        }
78
79        /// Sets the full request, replacing any prior values.
80        pub fn with_request<V: Into<crate::model::AnalyzeSentimentRequest>>(
81            mut self,
82            v: V,
83        ) -> Self {
84            self.0.request = v.into();
85            self
86        }
87
88        /// Sets all the options, replacing any prior values.
89        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
90            self.0.options = v.into();
91            self
92        }
93
94        /// Sends the request.
95        pub async fn send(self) -> Result<crate::model::AnalyzeSentimentResponse> {
96            (*self.0.stub)
97                .analyze_sentiment(self.0.request, self.0.options)
98                .await
99                .map(gax::response::Response::into_body)
100        }
101
102        /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
103        pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
104            mut self,
105            v: T,
106        ) -> Self {
107            self.0.request.document = v.into();
108            self
109        }
110
111        /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
112        pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
113            self.0.request.encoding_type = v.into();
114            self
115        }
116    }
117
118    #[doc(hidden)]
119    impl gax::options::internal::RequestBuilder for AnalyzeSentiment {
120        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
121            &mut self.0.options
122        }
123    }
124
125    /// The request builder for [LanguageService::analyze_entities][super::super::client::LanguageService::analyze_entities] calls.
126    #[derive(Clone, Debug)]
127    pub struct AnalyzeEntities(RequestBuilder<crate::model::AnalyzeEntitiesRequest>);
128
129    impl AnalyzeEntities {
130        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
131            Self(RequestBuilder::new(stub))
132        }
133
134        /// Sets the full request, replacing any prior values.
135        pub fn with_request<V: Into<crate::model::AnalyzeEntitiesRequest>>(mut self, v: V) -> Self {
136            self.0.request = v.into();
137            self
138        }
139
140        /// Sets all the options, replacing any prior values.
141        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
142            self.0.options = v.into();
143            self
144        }
145
146        /// Sends the request.
147        pub async fn send(self) -> Result<crate::model::AnalyzeEntitiesResponse> {
148            (*self.0.stub)
149                .analyze_entities(self.0.request, self.0.options)
150                .await
151                .map(gax::response::Response::into_body)
152        }
153
154        /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
155        pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
156            mut self,
157            v: T,
158        ) -> Self {
159            self.0.request.document = v.into();
160            self
161        }
162
163        /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
164        pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
165            self.0.request.encoding_type = v.into();
166            self
167        }
168    }
169
170    #[doc(hidden)]
171    impl gax::options::internal::RequestBuilder for AnalyzeEntities {
172        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
173            &mut self.0.options
174        }
175    }
176
177    /// The request builder for [LanguageService::classify_text][super::super::client::LanguageService::classify_text] calls.
178    #[derive(Clone, Debug)]
179    pub struct ClassifyText(RequestBuilder<crate::model::ClassifyTextRequest>);
180
181    impl ClassifyText {
182        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
183            Self(RequestBuilder::new(stub))
184        }
185
186        /// Sets the full request, replacing any prior values.
187        pub fn with_request<V: Into<crate::model::ClassifyTextRequest>>(mut self, v: V) -> Self {
188            self.0.request = v.into();
189            self
190        }
191
192        /// Sets all the options, replacing any prior values.
193        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
194            self.0.options = v.into();
195            self
196        }
197
198        /// Sends the request.
199        pub async fn send(self) -> Result<crate::model::ClassifyTextResponse> {
200            (*self.0.stub)
201                .classify_text(self.0.request, self.0.options)
202                .await
203                .map(gax::response::Response::into_body)
204        }
205
206        /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
207        pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
208            mut self,
209            v: T,
210        ) -> Self {
211            self.0.request.document = v.into();
212            self
213        }
214    }
215
216    #[doc(hidden)]
217    impl gax::options::internal::RequestBuilder for ClassifyText {
218        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
219            &mut self.0.options
220        }
221    }
222
223    /// The request builder for [LanguageService::moderate_text][super::super::client::LanguageService::moderate_text] calls.
224    #[derive(Clone, Debug)]
225    pub struct ModerateText(RequestBuilder<crate::model::ModerateTextRequest>);
226
227    impl ModerateText {
228        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
229            Self(RequestBuilder::new(stub))
230        }
231
232        /// Sets the full request, replacing any prior values.
233        pub fn with_request<V: Into<crate::model::ModerateTextRequest>>(mut self, v: V) -> Self {
234            self.0.request = v.into();
235            self
236        }
237
238        /// Sets all the options, replacing any prior values.
239        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
240            self.0.options = v.into();
241            self
242        }
243
244        /// Sends the request.
245        pub async fn send(self) -> Result<crate::model::ModerateTextResponse> {
246            (*self.0.stub)
247                .moderate_text(self.0.request, self.0.options)
248                .await
249                .map(gax::response::Response::into_body)
250        }
251
252        /// Sets the value of [document][crate::model::ModerateTextRequest::document].
253        pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
254            mut self,
255            v: T,
256        ) -> Self {
257            self.0.request.document = v.into();
258            self
259        }
260
261        /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
262        pub fn set_model_version<T: Into<crate::model::moderate_text_request::ModelVersion>>(
263            mut self,
264            v: T,
265        ) -> Self {
266            self.0.request.model_version = v.into();
267            self
268        }
269    }
270
271    #[doc(hidden)]
272    impl gax::options::internal::RequestBuilder for ModerateText {
273        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
274            &mut self.0.options
275        }
276    }
277
278    /// The request builder for [LanguageService::annotate_text][super::super::client::LanguageService::annotate_text] calls.
279    #[derive(Clone, Debug)]
280    pub struct AnnotateText(RequestBuilder<crate::model::AnnotateTextRequest>);
281
282    impl AnnotateText {
283        pub(crate) fn new(stub: Arc<dyn super::super::stub::dynamic::LanguageService>) -> Self {
284            Self(RequestBuilder::new(stub))
285        }
286
287        /// Sets the full request, replacing any prior values.
288        pub fn with_request<V: Into<crate::model::AnnotateTextRequest>>(mut self, v: V) -> Self {
289            self.0.request = v.into();
290            self
291        }
292
293        /// Sets all the options, replacing any prior values.
294        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
295            self.0.options = v.into();
296            self
297        }
298
299        /// Sends the request.
300        pub async fn send(self) -> Result<crate::model::AnnotateTextResponse> {
301            (*self.0.stub)
302                .annotate_text(self.0.request, self.0.options)
303                .await
304                .map(gax::response::Response::into_body)
305        }
306
307        /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
308        pub fn set_document<T: Into<std::option::Option<crate::model::Document>>>(
309            mut self,
310            v: T,
311        ) -> Self {
312            self.0.request.document = v.into();
313            self
314        }
315
316        /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
317        pub fn set_features<
318            T: Into<std::option::Option<crate::model::annotate_text_request::Features>>,
319        >(
320            mut self,
321            v: T,
322        ) -> Self {
323            self.0.request.features = v.into();
324            self
325        }
326
327        /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
328        pub fn set_encoding_type<T: Into<crate::model::EncodingType>>(mut self, v: T) -> Self {
329            self.0.request.encoding_type = v.into();
330            self
331        }
332    }
333
334    #[doc(hidden)]
335    impl gax::options::internal::RequestBuilder for AnnotateText {
336        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
337            &mut self.0.options
338        }
339    }
340}