google_cloud_language_v2/
model.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
17#![allow(rustdoc::redundant_explicit_links)]
18#![allow(rustdoc::broken_intra_doc_links)]
19#![no_implicit_prelude]
20extern crate async_trait;
21extern crate bytes;
22extern crate gax;
23extern crate gaxi;
24extern crate lazy_static;
25extern crate reqwest;
26extern crate serde;
27extern crate serde_json;
28extern crate serde_with;
29extern crate std;
30extern crate tracing;
31extern crate wkt;
32
33/// Represents the input to API methods.
34#[derive(Clone, Debug, Default, PartialEq)]
35#[non_exhaustive]
36pub struct Document {
37    /// Required. If the type is not set or is `TYPE_UNSPECIFIED`,
38    /// returns an `INVALID_ARGUMENT` error.
39    pub r#type: crate::model::document::Type,
40
41    /// Optional. The language of the document (if not specified, the language is
42    /// automatically detected). Both ISO and BCP-47 language codes are
43    /// accepted.\<br\>
44    /// [Language
45    /// Support](https://cloud.google.com/natural-language/docs/languages) lists
46    /// currently supported languages for each API method. If the language (either
47    /// specified by the caller or automatically detected) is not supported by the
48    /// called API method, an `INVALID_ARGUMENT` error is returned.
49    pub language_code: std::string::String,
50
51    /// The source of the document: a string containing the content or a
52    /// Google Cloud Storage URI.
53    pub source: std::option::Option<crate::model::document::Source>,
54
55    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
56}
57
58impl Document {
59    pub fn new() -> Self {
60        std::default::Default::default()
61    }
62
63    /// Sets the value of [r#type][crate::model::Document::type].
64    pub fn set_type<T: std::convert::Into<crate::model::document::Type>>(mut self, v: T) -> Self {
65        self.r#type = v.into();
66        self
67    }
68
69    /// Sets the value of [language_code][crate::model::Document::language_code].
70    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
71        self.language_code = v.into();
72        self
73    }
74
75    /// Sets the value of [source][crate::model::Document::source].
76    ///
77    /// Note that all the setters affecting `source` are mutually
78    /// exclusive.
79    pub fn set_source<
80        T: std::convert::Into<std::option::Option<crate::model::document::Source>>,
81    >(
82        mut self,
83        v: T,
84    ) -> Self {
85        self.source = v.into();
86        self
87    }
88
89    /// The value of [source][crate::model::Document::source]
90    /// if it holds a `Content`, `None` if the field is not set or
91    /// holds a different branch.
92    pub fn content(&self) -> std::option::Option<&std::string::String> {
93        #[allow(unreachable_patterns)]
94        self.source.as_ref().and_then(|v| match v {
95            crate::model::document::Source::Content(v) => std::option::Option::Some(v),
96            _ => std::option::Option::None,
97        })
98    }
99
100    /// Sets the value of [source][crate::model::Document::source]
101    /// to hold a `Content`.
102    ///
103    /// Note that all the setters affecting `source` are
104    /// mutually exclusive.
105    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
106        self.source = std::option::Option::Some(crate::model::document::Source::Content(v.into()));
107        self
108    }
109
110    /// The value of [source][crate::model::Document::source]
111    /// if it holds a `GcsContentUri`, `None` if the field is not set or
112    /// holds a different branch.
113    pub fn gcs_content_uri(&self) -> std::option::Option<&std::string::String> {
114        #[allow(unreachable_patterns)]
115        self.source.as_ref().and_then(|v| match v {
116            crate::model::document::Source::GcsContentUri(v) => std::option::Option::Some(v),
117            _ => std::option::Option::None,
118        })
119    }
120
121    /// Sets the value of [source][crate::model::Document::source]
122    /// to hold a `GcsContentUri`.
123    ///
124    /// Note that all the setters affecting `source` are
125    /// mutually exclusive.
126    pub fn set_gcs_content_uri<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
127        self.source =
128            std::option::Option::Some(crate::model::document::Source::GcsContentUri(v.into()));
129        self
130    }
131}
132
133impl wkt::message::Message for Document {
134    fn typename() -> &'static str {
135        "type.googleapis.com/google.cloud.language.v2.Document"
136    }
137}
138
139#[doc(hidden)]
140impl<'de> serde::de::Deserialize<'de> for Document {
141    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
142    where
143        D: serde::Deserializer<'de>,
144    {
145        #[allow(non_camel_case_types)]
146        #[doc(hidden)]
147        #[derive(PartialEq, Eq, Hash)]
148        enum __FieldTag {
149            __type,
150            __content,
151            __gcs_content_uri,
152            __language_code,
153            Unknown(std::string::String),
154        }
155        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
156            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
157            where
158                D: serde::Deserializer<'de>,
159            {
160                struct Visitor;
161                impl<'de> serde::de::Visitor<'de> for Visitor {
162                    type Value = __FieldTag;
163                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
164                        formatter.write_str("a field name for Document")
165                    }
166                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
167                    where
168                        E: serde::de::Error,
169                    {
170                        use std::result::Result::Ok;
171                        use std::string::ToString;
172                        match value {
173                            "type" => Ok(__FieldTag::__type),
174                            "content" => Ok(__FieldTag::__content),
175                            "gcsContentUri" => Ok(__FieldTag::__gcs_content_uri),
176                            "gcs_content_uri" => Ok(__FieldTag::__gcs_content_uri),
177                            "languageCode" => Ok(__FieldTag::__language_code),
178                            "language_code" => Ok(__FieldTag::__language_code),
179                            _ => Ok(__FieldTag::Unknown(value.to_string())),
180                        }
181                    }
182                }
183                deserializer.deserialize_identifier(Visitor)
184            }
185        }
186        struct Visitor;
187        impl<'de> serde::de::Visitor<'de> for Visitor {
188            type Value = Document;
189            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
190                formatter.write_str("struct Document")
191            }
192            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
193            where
194                A: serde::de::MapAccess<'de>,
195            {
196                #[allow(unused_imports)]
197                use serde::de::Error;
198                use std::option::Option::Some;
199                let mut fields = std::collections::HashSet::new();
200                let mut result = Self::Value::new();
201                while let Some(tag) = map.next_key::<__FieldTag>()? {
202                    #[allow(clippy::match_single_binding)]
203                    match tag {
204                        __FieldTag::__type => {
205                            if !fields.insert(__FieldTag::__type) {
206                                return std::result::Result::Err(A::Error::duplicate_field(
207                                    "multiple values for type",
208                                ));
209                            }
210                            result.r#type = map
211                                .next_value::<std::option::Option<crate::model::document::Type>>()?
212                                .unwrap_or_default();
213                        }
214                        __FieldTag::__content => {
215                            if !fields.insert(__FieldTag::__content) {
216                                return std::result::Result::Err(A::Error::duplicate_field(
217                                    "multiple values for content",
218                                ));
219                            }
220                            if result.source.is_some() {
221                                return std::result::Result::Err(A::Error::duplicate_field(
222                                    "multiple values for `source`, a oneof with full ID .google.cloud.language.v2.Document.content, latest field was content",
223                                ));
224                            }
225                            result.source =
226                                std::option::Option::Some(crate::model::document::Source::Content(
227                                    map.next_value::<std::option::Option<std::string::String>>()?
228                                        .unwrap_or_default(),
229                                ));
230                        }
231                        __FieldTag::__gcs_content_uri => {
232                            if !fields.insert(__FieldTag::__gcs_content_uri) {
233                                return std::result::Result::Err(A::Error::duplicate_field(
234                                    "multiple values for gcs_content_uri",
235                                ));
236                            }
237                            if result.source.is_some() {
238                                return std::result::Result::Err(A::Error::duplicate_field(
239                                    "multiple values for `source`, a oneof with full ID .google.cloud.language.v2.Document.gcs_content_uri, latest field was gcsContentUri",
240                                ));
241                            }
242                            result.source = std::option::Option::Some(
243                                crate::model::document::Source::GcsContentUri(
244                                    map.next_value::<std::option::Option<std::string::String>>()?
245                                        .unwrap_or_default(),
246                                ),
247                            );
248                        }
249                        __FieldTag::__language_code => {
250                            if !fields.insert(__FieldTag::__language_code) {
251                                return std::result::Result::Err(A::Error::duplicate_field(
252                                    "multiple values for language_code",
253                                ));
254                            }
255                            result.language_code = map
256                                .next_value::<std::option::Option<std::string::String>>()?
257                                .unwrap_or_default();
258                        }
259                        __FieldTag::Unknown(key) => {
260                            let value = map.next_value::<serde_json::Value>()?;
261                            result._unknown_fields.insert(key, value);
262                        }
263                    }
264                }
265                std::result::Result::Ok(result)
266            }
267        }
268        deserializer.deserialize_any(Visitor)
269    }
270}
271
272#[doc(hidden)]
273impl serde::ser::Serialize for Document {
274    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
275    where
276        S: serde::ser::Serializer,
277    {
278        use serde::ser::SerializeMap;
279        #[allow(unused_imports)]
280        use std::option::Option::Some;
281        let mut state = serializer.serialize_map(std::option::Option::None)?;
282        if !wkt::internal::is_default(&self.r#type) {
283            state.serialize_entry("type", &self.r#type)?;
284        }
285        if let Some(value) = self.content() {
286            state.serialize_entry("content", value)?;
287        }
288        if let Some(value) = self.gcs_content_uri() {
289            state.serialize_entry("gcsContentUri", value)?;
290        }
291        if !self.language_code.is_empty() {
292            state.serialize_entry("languageCode", &self.language_code)?;
293        }
294        if !self._unknown_fields.is_empty() {
295            for (key, value) in self._unknown_fields.iter() {
296                state.serialize_entry(key, &value)?;
297            }
298        }
299        state.end()
300    }
301}
302
303/// Defines additional types related to [Document].
304pub mod document {
305    #[allow(unused_imports)]
306    use super::*;
307
308    /// The document types enum.
309    ///
310    /// # Working with unknown values
311    ///
312    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
313    /// additional enum variants at any time. Adding new variants is not considered
314    /// a breaking change. Applications should write their code in anticipation of:
315    ///
316    /// - New values appearing in future releases of the client library, **and**
317    /// - New values received dynamically, without application changes.
318    ///
319    /// Please consult the [Working with enums] section in the user guide for some
320    /// guidelines.
321    ///
322    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
323    #[derive(Clone, Debug, PartialEq)]
324    #[non_exhaustive]
325    pub enum Type {
326        /// The content type is not specified.
327        Unspecified,
328        /// Plain text
329        PlainText,
330        /// HTML
331        Html,
332        /// If set, the enum was initialized with an unknown value.
333        ///
334        /// Applications can examine the value using [Type::value] or
335        /// [Type::name].
336        UnknownValue(r#type::UnknownValue),
337    }
338
339    #[doc(hidden)]
340    pub mod r#type {
341        #[allow(unused_imports)]
342        use super::*;
343        #[derive(Clone, Debug, PartialEq)]
344        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
345    }
346
347    impl Type {
348        /// Gets the enum value.
349        ///
350        /// Returns `None` if the enum contains an unknown value deserialized from
351        /// the string representation of enums.
352        pub fn value(&self) -> std::option::Option<i32> {
353            match self {
354                Self::Unspecified => std::option::Option::Some(0),
355                Self::PlainText => std::option::Option::Some(1),
356                Self::Html => std::option::Option::Some(2),
357                Self::UnknownValue(u) => u.0.value(),
358            }
359        }
360
361        /// Gets the enum value as a string.
362        ///
363        /// Returns `None` if the enum contains an unknown value deserialized from
364        /// the integer representation of enums.
365        pub fn name(&self) -> std::option::Option<&str> {
366            match self {
367                Self::Unspecified => std::option::Option::Some("TYPE_UNSPECIFIED"),
368                Self::PlainText => std::option::Option::Some("PLAIN_TEXT"),
369                Self::Html => std::option::Option::Some("HTML"),
370                Self::UnknownValue(u) => u.0.name(),
371            }
372        }
373    }
374
375    impl std::default::Default for Type {
376        fn default() -> Self {
377            use std::convert::From;
378            Self::from(0)
379        }
380    }
381
382    impl std::fmt::Display for Type {
383        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
384            wkt::internal::display_enum(f, self.name(), self.value())
385        }
386    }
387
388    impl std::convert::From<i32> for Type {
389        fn from(value: i32) -> Self {
390            match value {
391                0 => Self::Unspecified,
392                1 => Self::PlainText,
393                2 => Self::Html,
394                _ => Self::UnknownValue(r#type::UnknownValue(
395                    wkt::internal::UnknownEnumValue::Integer(value),
396                )),
397            }
398        }
399    }
400
401    impl std::convert::From<&str> for Type {
402        fn from(value: &str) -> Self {
403            use std::string::ToString;
404            match value {
405                "TYPE_UNSPECIFIED" => Self::Unspecified,
406                "PLAIN_TEXT" => Self::PlainText,
407                "HTML" => Self::Html,
408                _ => Self::UnknownValue(r#type::UnknownValue(
409                    wkt::internal::UnknownEnumValue::String(value.to_string()),
410                )),
411            }
412        }
413    }
414
415    impl serde::ser::Serialize for Type {
416        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
417        where
418            S: serde::Serializer,
419        {
420            match self {
421                Self::Unspecified => serializer.serialize_i32(0),
422                Self::PlainText => serializer.serialize_i32(1),
423                Self::Html => serializer.serialize_i32(2),
424                Self::UnknownValue(u) => u.0.serialize(serializer),
425            }
426        }
427    }
428
429    impl<'de> serde::de::Deserialize<'de> for Type {
430        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
431        where
432            D: serde::Deserializer<'de>,
433        {
434            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
435                ".google.cloud.language.v2.Document.Type",
436            ))
437        }
438    }
439
440    /// The source of the document: a string containing the content or a
441    /// Google Cloud Storage URI.
442    #[derive(Clone, Debug, PartialEq)]
443    #[non_exhaustive]
444    pub enum Source {
445        /// The content of the input in string format.
446        /// Cloud audit logging exempt since it is based on user data.
447        Content(std::string::String),
448        /// The Google Cloud Storage URI where the file content is located.
449        /// This URI must be of the form: gs://bucket_name/object_name. For more
450        /// details, see <https://cloud.google.com/storage/docs/reference-uris>.
451        /// NOTE: Cloud Storage object versioning is not supported.
452        GcsContentUri(std::string::String),
453    }
454}
455
456/// Represents a sentence in the input document.
457#[derive(Clone, Debug, Default, PartialEq)]
458#[non_exhaustive]
459pub struct Sentence {
460    /// The sentence text.
461    pub text: std::option::Option<crate::model::TextSpan>,
462
463    /// For calls to [AnalyzeSentiment][] or if
464    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]
465    /// is set to true, this field will contain the sentiment for the sentence.
466    ///
467    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
468    pub sentiment: std::option::Option<crate::model::Sentiment>,
469
470    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
471}
472
473impl Sentence {
474    pub fn new() -> Self {
475        std::default::Default::default()
476    }
477
478    /// Sets the value of [text][crate::model::Sentence::text].
479    pub fn set_text<T>(mut self, v: T) -> Self
480    where
481        T: std::convert::Into<crate::model::TextSpan>,
482    {
483        self.text = std::option::Option::Some(v.into());
484        self
485    }
486
487    /// Sets or clears the value of [text][crate::model::Sentence::text].
488    pub fn set_or_clear_text<T>(mut self, v: std::option::Option<T>) -> Self
489    where
490        T: std::convert::Into<crate::model::TextSpan>,
491    {
492        self.text = v.map(|x| x.into());
493        self
494    }
495
496    /// Sets the value of [sentiment][crate::model::Sentence::sentiment].
497    pub fn set_sentiment<T>(mut self, v: T) -> Self
498    where
499        T: std::convert::Into<crate::model::Sentiment>,
500    {
501        self.sentiment = std::option::Option::Some(v.into());
502        self
503    }
504
505    /// Sets or clears the value of [sentiment][crate::model::Sentence::sentiment].
506    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
507    where
508        T: std::convert::Into<crate::model::Sentiment>,
509    {
510        self.sentiment = v.map(|x| x.into());
511        self
512    }
513}
514
515impl wkt::message::Message for Sentence {
516    fn typename() -> &'static str {
517        "type.googleapis.com/google.cloud.language.v2.Sentence"
518    }
519}
520
521#[doc(hidden)]
522impl<'de> serde::de::Deserialize<'de> for Sentence {
523    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
524    where
525        D: serde::Deserializer<'de>,
526    {
527        #[allow(non_camel_case_types)]
528        #[doc(hidden)]
529        #[derive(PartialEq, Eq, Hash)]
530        enum __FieldTag {
531            __text,
532            __sentiment,
533            Unknown(std::string::String),
534        }
535        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
536            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
537            where
538                D: serde::Deserializer<'de>,
539            {
540                struct Visitor;
541                impl<'de> serde::de::Visitor<'de> for Visitor {
542                    type Value = __FieldTag;
543                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
544                        formatter.write_str("a field name for Sentence")
545                    }
546                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
547                    where
548                        E: serde::de::Error,
549                    {
550                        use std::result::Result::Ok;
551                        use std::string::ToString;
552                        match value {
553                            "text" => Ok(__FieldTag::__text),
554                            "sentiment" => Ok(__FieldTag::__sentiment),
555                            _ => Ok(__FieldTag::Unknown(value.to_string())),
556                        }
557                    }
558                }
559                deserializer.deserialize_identifier(Visitor)
560            }
561        }
562        struct Visitor;
563        impl<'de> serde::de::Visitor<'de> for Visitor {
564            type Value = Sentence;
565            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
566                formatter.write_str("struct Sentence")
567            }
568            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
569            where
570                A: serde::de::MapAccess<'de>,
571            {
572                #[allow(unused_imports)]
573                use serde::de::Error;
574                use std::option::Option::Some;
575                let mut fields = std::collections::HashSet::new();
576                let mut result = Self::Value::new();
577                while let Some(tag) = map.next_key::<__FieldTag>()? {
578                    #[allow(clippy::match_single_binding)]
579                    match tag {
580                        __FieldTag::__text => {
581                            if !fields.insert(__FieldTag::__text) {
582                                return std::result::Result::Err(A::Error::duplicate_field(
583                                    "multiple values for text",
584                                ));
585                            }
586                            result.text =
587                                map.next_value::<std::option::Option<crate::model::TextSpan>>()?;
588                        }
589                        __FieldTag::__sentiment => {
590                            if !fields.insert(__FieldTag::__sentiment) {
591                                return std::result::Result::Err(A::Error::duplicate_field(
592                                    "multiple values for sentiment",
593                                ));
594                            }
595                            result.sentiment =
596                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
597                        }
598                        __FieldTag::Unknown(key) => {
599                            let value = map.next_value::<serde_json::Value>()?;
600                            result._unknown_fields.insert(key, value);
601                        }
602                    }
603                }
604                std::result::Result::Ok(result)
605            }
606        }
607        deserializer.deserialize_any(Visitor)
608    }
609}
610
611#[doc(hidden)]
612impl serde::ser::Serialize for Sentence {
613    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
614    where
615        S: serde::ser::Serializer,
616    {
617        use serde::ser::SerializeMap;
618        #[allow(unused_imports)]
619        use std::option::Option::Some;
620        let mut state = serializer.serialize_map(std::option::Option::None)?;
621        if self.text.is_some() {
622            state.serialize_entry("text", &self.text)?;
623        }
624        if self.sentiment.is_some() {
625            state.serialize_entry("sentiment", &self.sentiment)?;
626        }
627        if !self._unknown_fields.is_empty() {
628            for (key, value) in self._unknown_fields.iter() {
629                state.serialize_entry(key, &value)?;
630            }
631        }
632        state.end()
633    }
634}
635
636/// Represents a phrase in the text that is a known entity, such as
637/// a person, an organization, or location. The API associates information, such
638/// as probability and mentions, with entities.
639#[derive(Clone, Debug, Default, PartialEq)]
640#[non_exhaustive]
641pub struct Entity {
642    /// The representative name for the entity.
643    pub name: std::string::String,
644
645    /// The entity type.
646    pub r#type: crate::model::entity::Type,
647
648    /// Metadata associated with the entity.
649    ///
650    /// For the metadata
651    /// associated with other entity types, see the Type table below.
652    pub metadata: std::collections::HashMap<std::string::String, std::string::String>,
653
654    /// The mentions of this entity in the input document. The API currently
655    /// supports proper noun mentions.
656    pub mentions: std::vec::Vec<crate::model::EntityMention>,
657
658    /// For calls to [AnalyzeEntitySentiment][] or if
659    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
660    /// is set to true, this field will contain the aggregate sentiment expressed
661    /// for this entity in the provided document.
662    pub sentiment: std::option::Option<crate::model::Sentiment>,
663
664    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
665}
666
667impl Entity {
668    pub fn new() -> Self {
669        std::default::Default::default()
670    }
671
672    /// Sets the value of [name][crate::model::Entity::name].
673    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
674        self.name = v.into();
675        self
676    }
677
678    /// Sets the value of [r#type][crate::model::Entity::type].
679    pub fn set_type<T: std::convert::Into<crate::model::entity::Type>>(mut self, v: T) -> Self {
680        self.r#type = v.into();
681        self
682    }
683
684    /// Sets the value of [metadata][crate::model::Entity::metadata].
685    pub fn set_metadata<T, K, V>(mut self, v: T) -> Self
686    where
687        T: std::iter::IntoIterator<Item = (K, V)>,
688        K: std::convert::Into<std::string::String>,
689        V: std::convert::Into<std::string::String>,
690    {
691        use std::iter::Iterator;
692        self.metadata = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
693        self
694    }
695
696    /// Sets the value of [mentions][crate::model::Entity::mentions].
697    pub fn set_mentions<T, V>(mut self, v: T) -> Self
698    where
699        T: std::iter::IntoIterator<Item = V>,
700        V: std::convert::Into<crate::model::EntityMention>,
701    {
702        use std::iter::Iterator;
703        self.mentions = v.into_iter().map(|i| i.into()).collect();
704        self
705    }
706
707    /// Sets the value of [sentiment][crate::model::Entity::sentiment].
708    pub fn set_sentiment<T>(mut self, v: T) -> Self
709    where
710        T: std::convert::Into<crate::model::Sentiment>,
711    {
712        self.sentiment = std::option::Option::Some(v.into());
713        self
714    }
715
716    /// Sets or clears the value of [sentiment][crate::model::Entity::sentiment].
717    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
718    where
719        T: std::convert::Into<crate::model::Sentiment>,
720    {
721        self.sentiment = v.map(|x| x.into());
722        self
723    }
724}
725
726impl wkt::message::Message for Entity {
727    fn typename() -> &'static str {
728        "type.googleapis.com/google.cloud.language.v2.Entity"
729    }
730}
731
732#[doc(hidden)]
733impl<'de> serde::de::Deserialize<'de> for Entity {
734    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
735    where
736        D: serde::Deserializer<'de>,
737    {
738        #[allow(non_camel_case_types)]
739        #[doc(hidden)]
740        #[derive(PartialEq, Eq, Hash)]
741        enum __FieldTag {
742            __name,
743            __type,
744            __metadata,
745            __mentions,
746            __sentiment,
747            Unknown(std::string::String),
748        }
749        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
750            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
751            where
752                D: serde::Deserializer<'de>,
753            {
754                struct Visitor;
755                impl<'de> serde::de::Visitor<'de> for Visitor {
756                    type Value = __FieldTag;
757                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
758                        formatter.write_str("a field name for Entity")
759                    }
760                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
761                    where
762                        E: serde::de::Error,
763                    {
764                        use std::result::Result::Ok;
765                        use std::string::ToString;
766                        match value {
767                            "name" => Ok(__FieldTag::__name),
768                            "type" => Ok(__FieldTag::__type),
769                            "metadata" => Ok(__FieldTag::__metadata),
770                            "mentions" => Ok(__FieldTag::__mentions),
771                            "sentiment" => Ok(__FieldTag::__sentiment),
772                            _ => Ok(__FieldTag::Unknown(value.to_string())),
773                        }
774                    }
775                }
776                deserializer.deserialize_identifier(Visitor)
777            }
778        }
779        struct Visitor;
780        impl<'de> serde::de::Visitor<'de> for Visitor {
781            type Value = Entity;
782            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
783                formatter.write_str("struct Entity")
784            }
785            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
786            where
787                A: serde::de::MapAccess<'de>,
788            {
789                #[allow(unused_imports)]
790                use serde::de::Error;
791                use std::option::Option::Some;
792                let mut fields = std::collections::HashSet::new();
793                let mut result = Self::Value::new();
794                while let Some(tag) = map.next_key::<__FieldTag>()? {
795                    #[allow(clippy::match_single_binding)]
796                    match tag {
797                        __FieldTag::__name => {
798                            if !fields.insert(__FieldTag::__name) {
799                                return std::result::Result::Err(A::Error::duplicate_field(
800                                    "multiple values for name",
801                                ));
802                            }
803                            result.name = map
804                                .next_value::<std::option::Option<std::string::String>>()?
805                                .unwrap_or_default();
806                        }
807                        __FieldTag::__type => {
808                            if !fields.insert(__FieldTag::__type) {
809                                return std::result::Result::Err(A::Error::duplicate_field(
810                                    "multiple values for type",
811                                ));
812                            }
813                            result.r#type = map
814                                .next_value::<std::option::Option<crate::model::entity::Type>>()?
815                                .unwrap_or_default();
816                        }
817                        __FieldTag::__metadata => {
818                            if !fields.insert(__FieldTag::__metadata) {
819                                return std::result::Result::Err(A::Error::duplicate_field(
820                                    "multiple values for metadata",
821                                ));
822                            }
823                            result.metadata = map
824                                .next_value::<std::option::Option<
825                                    std::collections::HashMap<
826                                        std::string::String,
827                                        std::string::String,
828                                    >,
829                                >>()?
830                                .unwrap_or_default();
831                        }
832                        __FieldTag::__mentions => {
833                            if !fields.insert(__FieldTag::__mentions) {
834                                return std::result::Result::Err(A::Error::duplicate_field(
835                                    "multiple values for mentions",
836                                ));
837                            }
838                            result.mentions = map.next_value::<std::option::Option<std::vec::Vec<crate::model::EntityMention>>>()?.unwrap_or_default();
839                        }
840                        __FieldTag::__sentiment => {
841                            if !fields.insert(__FieldTag::__sentiment) {
842                                return std::result::Result::Err(A::Error::duplicate_field(
843                                    "multiple values for sentiment",
844                                ));
845                            }
846                            result.sentiment =
847                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
848                        }
849                        __FieldTag::Unknown(key) => {
850                            let value = map.next_value::<serde_json::Value>()?;
851                            result._unknown_fields.insert(key, value);
852                        }
853                    }
854                }
855                std::result::Result::Ok(result)
856            }
857        }
858        deserializer.deserialize_any(Visitor)
859    }
860}
861
862#[doc(hidden)]
863impl serde::ser::Serialize for Entity {
864    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
865    where
866        S: serde::ser::Serializer,
867    {
868        use serde::ser::SerializeMap;
869        #[allow(unused_imports)]
870        use std::option::Option::Some;
871        let mut state = serializer.serialize_map(std::option::Option::None)?;
872        if !self.name.is_empty() {
873            state.serialize_entry("name", &self.name)?;
874        }
875        if !wkt::internal::is_default(&self.r#type) {
876            state.serialize_entry("type", &self.r#type)?;
877        }
878        if !self.metadata.is_empty() {
879            state.serialize_entry("metadata", &self.metadata)?;
880        }
881        if !self.mentions.is_empty() {
882            state.serialize_entry("mentions", &self.mentions)?;
883        }
884        if self.sentiment.is_some() {
885            state.serialize_entry("sentiment", &self.sentiment)?;
886        }
887        if !self._unknown_fields.is_empty() {
888            for (key, value) in self._unknown_fields.iter() {
889                state.serialize_entry(key, &value)?;
890            }
891        }
892        state.end()
893    }
894}
895
896/// Defines additional types related to [Entity].
897pub mod entity {
898    #[allow(unused_imports)]
899    use super::*;
900
901    /// The type of the entity. The table
902    /// below lists the associated fields for entities that have different
903    /// metadata.
904    ///
905    /// # Working with unknown values
906    ///
907    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
908    /// additional enum variants at any time. Adding new variants is not considered
909    /// a breaking change. Applications should write their code in anticipation of:
910    ///
911    /// - New values appearing in future releases of the client library, **and**
912    /// - New values received dynamically, without application changes.
913    ///
914    /// Please consult the [Working with enums] section in the user guide for some
915    /// guidelines.
916    ///
917    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
918    #[derive(Clone, Debug, PartialEq)]
919    #[non_exhaustive]
920    pub enum Type {
921        /// Unknown
922        Unknown,
923        /// Person
924        Person,
925        /// Location
926        Location,
927        /// Organization
928        Organization,
929        /// Event
930        Event,
931        /// Artwork
932        WorkOfArt,
933        /// Consumer product
934        ConsumerGood,
935        /// Other types of entities
936        Other,
937        /// Phone number
938        ///
939        /// The metadata lists the phone number, formatted according to local
940        /// convention, plus whichever additional elements appear in the text:
941        ///
942        /// * `number` - the actual number, broken down into sections as per local
943        ///   convention
944        /// * `national_prefix` - country code, if detected
945        /// * `area_code` - region or area code, if detected
946        /// * `extension` - phone extension (to be dialed after connection), if
947        ///   detected
948        PhoneNumber,
949        /// Address
950        ///
951        /// The metadata identifies the street number and locality plus whichever
952        /// additional elements appear in the text:
953        ///
954        /// * `street_number` - street number
955        /// * `locality` - city or town
956        /// * `street_name` - street/route name, if detected
957        /// * `postal_code` - postal code, if detected
958        /// * `country` - country, if detected
959        /// * `broad_region` - administrative area, such as the state, if detected
960        /// * `narrow_region` - smaller administrative area, such as county, if
961        ///   detected
962        /// * `sublocality` - used in Asian addresses to demark a district within a
963        ///   city, if detected
964        Address,
965        /// Date
966        ///
967        /// The metadata identifies the components of the date:
968        ///
969        /// * `year` - four digit year, if detected
970        /// * `month` - two digit month number, if detected
971        /// * `day` - two digit day number, if detected
972        Date,
973        /// Number
974        ///
975        /// The metadata is the number itself.
976        Number,
977        /// Price
978        ///
979        /// The metadata identifies the `value` and `currency`.
980        Price,
981        /// If set, the enum was initialized with an unknown value.
982        ///
983        /// Applications can examine the value using [Type::value] or
984        /// [Type::name].
985        UnknownValue(r#type::UnknownValue),
986    }
987
988    #[doc(hidden)]
989    pub mod r#type {
990        #[allow(unused_imports)]
991        use super::*;
992        #[derive(Clone, Debug, PartialEq)]
993        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
994    }
995
996    impl Type {
997        /// Gets the enum value.
998        ///
999        /// Returns `None` if the enum contains an unknown value deserialized from
1000        /// the string representation of enums.
1001        pub fn value(&self) -> std::option::Option<i32> {
1002            match self {
1003                Self::Unknown => std::option::Option::Some(0),
1004                Self::Person => std::option::Option::Some(1),
1005                Self::Location => std::option::Option::Some(2),
1006                Self::Organization => std::option::Option::Some(3),
1007                Self::Event => std::option::Option::Some(4),
1008                Self::WorkOfArt => std::option::Option::Some(5),
1009                Self::ConsumerGood => std::option::Option::Some(6),
1010                Self::Other => std::option::Option::Some(7),
1011                Self::PhoneNumber => std::option::Option::Some(9),
1012                Self::Address => std::option::Option::Some(10),
1013                Self::Date => std::option::Option::Some(11),
1014                Self::Number => std::option::Option::Some(12),
1015                Self::Price => std::option::Option::Some(13),
1016                Self::UnknownValue(u) => u.0.value(),
1017            }
1018        }
1019
1020        /// Gets the enum value as a string.
1021        ///
1022        /// Returns `None` if the enum contains an unknown value deserialized from
1023        /// the integer representation of enums.
1024        pub fn name(&self) -> std::option::Option<&str> {
1025            match self {
1026                Self::Unknown => std::option::Option::Some("UNKNOWN"),
1027                Self::Person => std::option::Option::Some("PERSON"),
1028                Self::Location => std::option::Option::Some("LOCATION"),
1029                Self::Organization => std::option::Option::Some("ORGANIZATION"),
1030                Self::Event => std::option::Option::Some("EVENT"),
1031                Self::WorkOfArt => std::option::Option::Some("WORK_OF_ART"),
1032                Self::ConsumerGood => std::option::Option::Some("CONSUMER_GOOD"),
1033                Self::Other => std::option::Option::Some("OTHER"),
1034                Self::PhoneNumber => std::option::Option::Some("PHONE_NUMBER"),
1035                Self::Address => std::option::Option::Some("ADDRESS"),
1036                Self::Date => std::option::Option::Some("DATE"),
1037                Self::Number => std::option::Option::Some("NUMBER"),
1038                Self::Price => std::option::Option::Some("PRICE"),
1039                Self::UnknownValue(u) => u.0.name(),
1040            }
1041        }
1042    }
1043
1044    impl std::default::Default for Type {
1045        fn default() -> Self {
1046            use std::convert::From;
1047            Self::from(0)
1048        }
1049    }
1050
1051    impl std::fmt::Display for Type {
1052        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1053            wkt::internal::display_enum(f, self.name(), self.value())
1054        }
1055    }
1056
1057    impl std::convert::From<i32> for Type {
1058        fn from(value: i32) -> Self {
1059            match value {
1060                0 => Self::Unknown,
1061                1 => Self::Person,
1062                2 => Self::Location,
1063                3 => Self::Organization,
1064                4 => Self::Event,
1065                5 => Self::WorkOfArt,
1066                6 => Self::ConsumerGood,
1067                7 => Self::Other,
1068                9 => Self::PhoneNumber,
1069                10 => Self::Address,
1070                11 => Self::Date,
1071                12 => Self::Number,
1072                13 => Self::Price,
1073                _ => Self::UnknownValue(r#type::UnknownValue(
1074                    wkt::internal::UnknownEnumValue::Integer(value),
1075                )),
1076            }
1077        }
1078    }
1079
1080    impl std::convert::From<&str> for Type {
1081        fn from(value: &str) -> Self {
1082            use std::string::ToString;
1083            match value {
1084                "UNKNOWN" => Self::Unknown,
1085                "PERSON" => Self::Person,
1086                "LOCATION" => Self::Location,
1087                "ORGANIZATION" => Self::Organization,
1088                "EVENT" => Self::Event,
1089                "WORK_OF_ART" => Self::WorkOfArt,
1090                "CONSUMER_GOOD" => Self::ConsumerGood,
1091                "OTHER" => Self::Other,
1092                "PHONE_NUMBER" => Self::PhoneNumber,
1093                "ADDRESS" => Self::Address,
1094                "DATE" => Self::Date,
1095                "NUMBER" => Self::Number,
1096                "PRICE" => Self::Price,
1097                _ => Self::UnknownValue(r#type::UnknownValue(
1098                    wkt::internal::UnknownEnumValue::String(value.to_string()),
1099                )),
1100            }
1101        }
1102    }
1103
1104    impl serde::ser::Serialize for Type {
1105        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1106        where
1107            S: serde::Serializer,
1108        {
1109            match self {
1110                Self::Unknown => serializer.serialize_i32(0),
1111                Self::Person => serializer.serialize_i32(1),
1112                Self::Location => serializer.serialize_i32(2),
1113                Self::Organization => serializer.serialize_i32(3),
1114                Self::Event => serializer.serialize_i32(4),
1115                Self::WorkOfArt => serializer.serialize_i32(5),
1116                Self::ConsumerGood => serializer.serialize_i32(6),
1117                Self::Other => serializer.serialize_i32(7),
1118                Self::PhoneNumber => serializer.serialize_i32(9),
1119                Self::Address => serializer.serialize_i32(10),
1120                Self::Date => serializer.serialize_i32(11),
1121                Self::Number => serializer.serialize_i32(12),
1122                Self::Price => serializer.serialize_i32(13),
1123                Self::UnknownValue(u) => u.0.serialize(serializer),
1124            }
1125        }
1126    }
1127
1128    impl<'de> serde::de::Deserialize<'de> for Type {
1129        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1130        where
1131            D: serde::Deserializer<'de>,
1132        {
1133            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
1134                ".google.cloud.language.v2.Entity.Type",
1135            ))
1136        }
1137    }
1138}
1139
1140/// Represents the feeling associated with the entire text or entities in
1141/// the text.
1142#[derive(Clone, Debug, Default, PartialEq)]
1143#[non_exhaustive]
1144pub struct Sentiment {
1145    /// A non-negative number in the [0, +inf) range, which represents
1146    /// the absolute magnitude of sentiment regardless of score (positive or
1147    /// negative).
1148    pub magnitude: f32,
1149
1150    /// Sentiment score between -1.0 (negative sentiment) and 1.0
1151    /// (positive sentiment).
1152    pub score: f32,
1153
1154    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1155}
1156
1157impl Sentiment {
1158    pub fn new() -> Self {
1159        std::default::Default::default()
1160    }
1161
1162    /// Sets the value of [magnitude][crate::model::Sentiment::magnitude].
1163    pub fn set_magnitude<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1164        self.magnitude = v.into();
1165        self
1166    }
1167
1168    /// Sets the value of [score][crate::model::Sentiment::score].
1169    pub fn set_score<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1170        self.score = v.into();
1171        self
1172    }
1173}
1174
1175impl wkt::message::Message for Sentiment {
1176    fn typename() -> &'static str {
1177        "type.googleapis.com/google.cloud.language.v2.Sentiment"
1178    }
1179}
1180
1181#[doc(hidden)]
1182impl<'de> serde::de::Deserialize<'de> for Sentiment {
1183    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1184    where
1185        D: serde::Deserializer<'de>,
1186    {
1187        #[allow(non_camel_case_types)]
1188        #[doc(hidden)]
1189        #[derive(PartialEq, Eq, Hash)]
1190        enum __FieldTag {
1191            __magnitude,
1192            __score,
1193            Unknown(std::string::String),
1194        }
1195        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1196            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1197            where
1198                D: serde::Deserializer<'de>,
1199            {
1200                struct Visitor;
1201                impl<'de> serde::de::Visitor<'de> for Visitor {
1202                    type Value = __FieldTag;
1203                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1204                        formatter.write_str("a field name for Sentiment")
1205                    }
1206                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1207                    where
1208                        E: serde::de::Error,
1209                    {
1210                        use std::result::Result::Ok;
1211                        use std::string::ToString;
1212                        match value {
1213                            "magnitude" => Ok(__FieldTag::__magnitude),
1214                            "score" => Ok(__FieldTag::__score),
1215                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1216                        }
1217                    }
1218                }
1219                deserializer.deserialize_identifier(Visitor)
1220            }
1221        }
1222        struct Visitor;
1223        impl<'de> serde::de::Visitor<'de> for Visitor {
1224            type Value = Sentiment;
1225            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1226                formatter.write_str("struct Sentiment")
1227            }
1228            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1229            where
1230                A: serde::de::MapAccess<'de>,
1231            {
1232                #[allow(unused_imports)]
1233                use serde::de::Error;
1234                use std::option::Option::Some;
1235                let mut fields = std::collections::HashSet::new();
1236                let mut result = Self::Value::new();
1237                while let Some(tag) = map.next_key::<__FieldTag>()? {
1238                    #[allow(clippy::match_single_binding)]
1239                    match tag {
1240                        __FieldTag::__magnitude => {
1241                            if !fields.insert(__FieldTag::__magnitude) {
1242                                return std::result::Result::Err(A::Error::duplicate_field(
1243                                    "multiple values for magnitude",
1244                                ));
1245                            }
1246                            struct __With(std::option::Option<f32>);
1247                            impl<'de> serde::de::Deserialize<'de> for __With {
1248                                fn deserialize<D>(
1249                                    deserializer: D,
1250                                ) -> std::result::Result<Self, D::Error>
1251                                where
1252                                    D: serde::de::Deserializer<'de>,
1253                                {
1254                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1255                                }
1256                            }
1257                            result.magnitude = map.next_value::<__With>()?.0.unwrap_or_default();
1258                        }
1259                        __FieldTag::__score => {
1260                            if !fields.insert(__FieldTag::__score) {
1261                                return std::result::Result::Err(A::Error::duplicate_field(
1262                                    "multiple values for score",
1263                                ));
1264                            }
1265                            struct __With(std::option::Option<f32>);
1266                            impl<'de> serde::de::Deserialize<'de> for __With {
1267                                fn deserialize<D>(
1268                                    deserializer: D,
1269                                ) -> std::result::Result<Self, D::Error>
1270                                where
1271                                    D: serde::de::Deserializer<'de>,
1272                                {
1273                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1274                                }
1275                            }
1276                            result.score = map.next_value::<__With>()?.0.unwrap_or_default();
1277                        }
1278                        __FieldTag::Unknown(key) => {
1279                            let value = map.next_value::<serde_json::Value>()?;
1280                            result._unknown_fields.insert(key, value);
1281                        }
1282                    }
1283                }
1284                std::result::Result::Ok(result)
1285            }
1286        }
1287        deserializer.deserialize_any(Visitor)
1288    }
1289}
1290
1291#[doc(hidden)]
1292impl serde::ser::Serialize for Sentiment {
1293    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1294    where
1295        S: serde::ser::Serializer,
1296    {
1297        use serde::ser::SerializeMap;
1298        #[allow(unused_imports)]
1299        use std::option::Option::Some;
1300        let mut state = serializer.serialize_map(std::option::Option::None)?;
1301        if !wkt::internal::is_default(&self.magnitude) {
1302            struct __With<'a>(&'a f32);
1303            impl<'a> serde::ser::Serialize for __With<'a> {
1304                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1305                where
1306                    S: serde::ser::Serializer,
1307                {
1308                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1309                }
1310            }
1311            state.serialize_entry("magnitude", &__With(&self.magnitude))?;
1312        }
1313        if !wkt::internal::is_default(&self.score) {
1314            struct __With<'a>(&'a f32);
1315            impl<'a> serde::ser::Serialize for __With<'a> {
1316                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1317                where
1318                    S: serde::ser::Serializer,
1319                {
1320                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1321                }
1322            }
1323            state.serialize_entry("score", &__With(&self.score))?;
1324        }
1325        if !self._unknown_fields.is_empty() {
1326            for (key, value) in self._unknown_fields.iter() {
1327                state.serialize_entry(key, &value)?;
1328            }
1329        }
1330        state.end()
1331    }
1332}
1333
1334/// Represents a mention for an entity in the text. Currently, proper noun
1335/// mentions are supported.
1336#[derive(Clone, Debug, Default, PartialEq)]
1337#[non_exhaustive]
1338pub struct EntityMention {
1339    /// The mention text.
1340    pub text: std::option::Option<crate::model::TextSpan>,
1341
1342    /// The type of the entity mention.
1343    pub r#type: crate::model::entity_mention::Type,
1344
1345    /// For calls to [AnalyzeEntitySentiment][] or if
1346    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
1347    /// is set to true, this field will contain the sentiment expressed for this
1348    /// mention of the entity in the provided document.
1349    pub sentiment: std::option::Option<crate::model::Sentiment>,
1350
1351    /// Probability score associated with the entity.
1352    ///
1353    /// The score shows the probability of the entity mention being the entity
1354    /// type. The score is in (0, 1] range.
1355    pub probability: f32,
1356
1357    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1358}
1359
1360impl EntityMention {
1361    pub fn new() -> Self {
1362        std::default::Default::default()
1363    }
1364
1365    /// Sets the value of [text][crate::model::EntityMention::text].
1366    pub fn set_text<T>(mut self, v: T) -> Self
1367    where
1368        T: std::convert::Into<crate::model::TextSpan>,
1369    {
1370        self.text = std::option::Option::Some(v.into());
1371        self
1372    }
1373
1374    /// Sets or clears the value of [text][crate::model::EntityMention::text].
1375    pub fn set_or_clear_text<T>(mut self, v: std::option::Option<T>) -> Self
1376    where
1377        T: std::convert::Into<crate::model::TextSpan>,
1378    {
1379        self.text = v.map(|x| x.into());
1380        self
1381    }
1382
1383    /// Sets the value of [r#type][crate::model::EntityMention::type].
1384    pub fn set_type<T: std::convert::Into<crate::model::entity_mention::Type>>(
1385        mut self,
1386        v: T,
1387    ) -> Self {
1388        self.r#type = v.into();
1389        self
1390    }
1391
1392    /// Sets the value of [sentiment][crate::model::EntityMention::sentiment].
1393    pub fn set_sentiment<T>(mut self, v: T) -> Self
1394    where
1395        T: std::convert::Into<crate::model::Sentiment>,
1396    {
1397        self.sentiment = std::option::Option::Some(v.into());
1398        self
1399    }
1400
1401    /// Sets or clears the value of [sentiment][crate::model::EntityMention::sentiment].
1402    pub fn set_or_clear_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
1403    where
1404        T: std::convert::Into<crate::model::Sentiment>,
1405    {
1406        self.sentiment = v.map(|x| x.into());
1407        self
1408    }
1409
1410    /// Sets the value of [probability][crate::model::EntityMention::probability].
1411    pub fn set_probability<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1412        self.probability = v.into();
1413        self
1414    }
1415}
1416
1417impl wkt::message::Message for EntityMention {
1418    fn typename() -> &'static str {
1419        "type.googleapis.com/google.cloud.language.v2.EntityMention"
1420    }
1421}
1422
1423#[doc(hidden)]
1424impl<'de> serde::de::Deserialize<'de> for EntityMention {
1425    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1426    where
1427        D: serde::Deserializer<'de>,
1428    {
1429        #[allow(non_camel_case_types)]
1430        #[doc(hidden)]
1431        #[derive(PartialEq, Eq, Hash)]
1432        enum __FieldTag {
1433            __text,
1434            __type,
1435            __sentiment,
1436            __probability,
1437            Unknown(std::string::String),
1438        }
1439        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1440            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1441            where
1442                D: serde::Deserializer<'de>,
1443            {
1444                struct Visitor;
1445                impl<'de> serde::de::Visitor<'de> for Visitor {
1446                    type Value = __FieldTag;
1447                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1448                        formatter.write_str("a field name for EntityMention")
1449                    }
1450                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1451                    where
1452                        E: serde::de::Error,
1453                    {
1454                        use std::result::Result::Ok;
1455                        use std::string::ToString;
1456                        match value {
1457                            "text" => Ok(__FieldTag::__text),
1458                            "type" => Ok(__FieldTag::__type),
1459                            "sentiment" => Ok(__FieldTag::__sentiment),
1460                            "probability" => Ok(__FieldTag::__probability),
1461                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1462                        }
1463                    }
1464                }
1465                deserializer.deserialize_identifier(Visitor)
1466            }
1467        }
1468        struct Visitor;
1469        impl<'de> serde::de::Visitor<'de> for Visitor {
1470            type Value = EntityMention;
1471            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1472                formatter.write_str("struct EntityMention")
1473            }
1474            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1475            where
1476                A: serde::de::MapAccess<'de>,
1477            {
1478                #[allow(unused_imports)]
1479                use serde::de::Error;
1480                use std::option::Option::Some;
1481                let mut fields = std::collections::HashSet::new();
1482                let mut result = Self::Value::new();
1483                while let Some(tag) = map.next_key::<__FieldTag>()? {
1484                    #[allow(clippy::match_single_binding)]
1485                    match tag {
1486                        __FieldTag::__text => {
1487                            if !fields.insert(__FieldTag::__text) {
1488                                return std::result::Result::Err(A::Error::duplicate_field(
1489                                    "multiple values for text",
1490                                ));
1491                            }
1492                            result.text =
1493                                map.next_value::<std::option::Option<crate::model::TextSpan>>()?;
1494                        }
1495                        __FieldTag::__type => {
1496                            if !fields.insert(__FieldTag::__type) {
1497                                return std::result::Result::Err(A::Error::duplicate_field(
1498                                    "multiple values for type",
1499                                ));
1500                            }
1501                            result.r#type = map.next_value::<std::option::Option<crate::model::entity_mention::Type>>()?.unwrap_or_default();
1502                        }
1503                        __FieldTag::__sentiment => {
1504                            if !fields.insert(__FieldTag::__sentiment) {
1505                                return std::result::Result::Err(A::Error::duplicate_field(
1506                                    "multiple values for sentiment",
1507                                ));
1508                            }
1509                            result.sentiment =
1510                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
1511                        }
1512                        __FieldTag::__probability => {
1513                            if !fields.insert(__FieldTag::__probability) {
1514                                return std::result::Result::Err(A::Error::duplicate_field(
1515                                    "multiple values for probability",
1516                                ));
1517                            }
1518                            struct __With(std::option::Option<f32>);
1519                            impl<'de> serde::de::Deserialize<'de> for __With {
1520                                fn deserialize<D>(
1521                                    deserializer: D,
1522                                ) -> std::result::Result<Self, D::Error>
1523                                where
1524                                    D: serde::de::Deserializer<'de>,
1525                                {
1526                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
1527                                }
1528                            }
1529                            result.probability = map.next_value::<__With>()?.0.unwrap_or_default();
1530                        }
1531                        __FieldTag::Unknown(key) => {
1532                            let value = map.next_value::<serde_json::Value>()?;
1533                            result._unknown_fields.insert(key, value);
1534                        }
1535                    }
1536                }
1537                std::result::Result::Ok(result)
1538            }
1539        }
1540        deserializer.deserialize_any(Visitor)
1541    }
1542}
1543
1544#[doc(hidden)]
1545impl serde::ser::Serialize for EntityMention {
1546    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1547    where
1548        S: serde::ser::Serializer,
1549    {
1550        use serde::ser::SerializeMap;
1551        #[allow(unused_imports)]
1552        use std::option::Option::Some;
1553        let mut state = serializer.serialize_map(std::option::Option::None)?;
1554        if self.text.is_some() {
1555            state.serialize_entry("text", &self.text)?;
1556        }
1557        if !wkt::internal::is_default(&self.r#type) {
1558            state.serialize_entry("type", &self.r#type)?;
1559        }
1560        if self.sentiment.is_some() {
1561            state.serialize_entry("sentiment", &self.sentiment)?;
1562        }
1563        if !wkt::internal::is_default(&self.probability) {
1564            struct __With<'a>(&'a f32);
1565            impl<'a> serde::ser::Serialize for __With<'a> {
1566                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1567                where
1568                    S: serde::ser::Serializer,
1569                {
1570                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
1571                }
1572            }
1573            state.serialize_entry("probability", &__With(&self.probability))?;
1574        }
1575        if !self._unknown_fields.is_empty() {
1576            for (key, value) in self._unknown_fields.iter() {
1577                state.serialize_entry(key, &value)?;
1578            }
1579        }
1580        state.end()
1581    }
1582}
1583
1584/// Defines additional types related to [EntityMention].
1585pub mod entity_mention {
1586    #[allow(unused_imports)]
1587    use super::*;
1588
1589    /// The supported types of mentions.
1590    ///
1591    /// # Working with unknown values
1592    ///
1593    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
1594    /// additional enum variants at any time. Adding new variants is not considered
1595    /// a breaking change. Applications should write their code in anticipation of:
1596    ///
1597    /// - New values appearing in future releases of the client library, **and**
1598    /// - New values received dynamically, without application changes.
1599    ///
1600    /// Please consult the [Working with enums] section in the user guide for some
1601    /// guidelines.
1602    ///
1603    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
1604    #[derive(Clone, Debug, PartialEq)]
1605    #[non_exhaustive]
1606    pub enum Type {
1607        /// Unknown
1608        Unknown,
1609        /// Proper name
1610        Proper,
1611        /// Common noun (or noun compound)
1612        Common,
1613        /// If set, the enum was initialized with an unknown value.
1614        ///
1615        /// Applications can examine the value using [Type::value] or
1616        /// [Type::name].
1617        UnknownValue(r#type::UnknownValue),
1618    }
1619
1620    #[doc(hidden)]
1621    pub mod r#type {
1622        #[allow(unused_imports)]
1623        use super::*;
1624        #[derive(Clone, Debug, PartialEq)]
1625        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
1626    }
1627
1628    impl Type {
1629        /// Gets the enum value.
1630        ///
1631        /// Returns `None` if the enum contains an unknown value deserialized from
1632        /// the string representation of enums.
1633        pub fn value(&self) -> std::option::Option<i32> {
1634            match self {
1635                Self::Unknown => std::option::Option::Some(0),
1636                Self::Proper => std::option::Option::Some(1),
1637                Self::Common => std::option::Option::Some(2),
1638                Self::UnknownValue(u) => u.0.value(),
1639            }
1640        }
1641
1642        /// Gets the enum value as a string.
1643        ///
1644        /// Returns `None` if the enum contains an unknown value deserialized from
1645        /// the integer representation of enums.
1646        pub fn name(&self) -> std::option::Option<&str> {
1647            match self {
1648                Self::Unknown => std::option::Option::Some("TYPE_UNKNOWN"),
1649                Self::Proper => std::option::Option::Some("PROPER"),
1650                Self::Common => std::option::Option::Some("COMMON"),
1651                Self::UnknownValue(u) => u.0.name(),
1652            }
1653        }
1654    }
1655
1656    impl std::default::Default for Type {
1657        fn default() -> Self {
1658            use std::convert::From;
1659            Self::from(0)
1660        }
1661    }
1662
1663    impl std::fmt::Display for Type {
1664        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1665            wkt::internal::display_enum(f, self.name(), self.value())
1666        }
1667    }
1668
1669    impl std::convert::From<i32> for Type {
1670        fn from(value: i32) -> Self {
1671            match value {
1672                0 => Self::Unknown,
1673                1 => Self::Proper,
1674                2 => Self::Common,
1675                _ => Self::UnknownValue(r#type::UnknownValue(
1676                    wkt::internal::UnknownEnumValue::Integer(value),
1677                )),
1678            }
1679        }
1680    }
1681
1682    impl std::convert::From<&str> for Type {
1683        fn from(value: &str) -> Self {
1684            use std::string::ToString;
1685            match value {
1686                "TYPE_UNKNOWN" => Self::Unknown,
1687                "PROPER" => Self::Proper,
1688                "COMMON" => Self::Common,
1689                _ => Self::UnknownValue(r#type::UnknownValue(
1690                    wkt::internal::UnknownEnumValue::String(value.to_string()),
1691                )),
1692            }
1693        }
1694    }
1695
1696    impl serde::ser::Serialize for Type {
1697        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1698        where
1699            S: serde::Serializer,
1700        {
1701            match self {
1702                Self::Unknown => serializer.serialize_i32(0),
1703                Self::Proper => serializer.serialize_i32(1),
1704                Self::Common => serializer.serialize_i32(2),
1705                Self::UnknownValue(u) => u.0.serialize(serializer),
1706            }
1707        }
1708    }
1709
1710    impl<'de> serde::de::Deserialize<'de> for Type {
1711        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1712        where
1713            D: serde::Deserializer<'de>,
1714        {
1715            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
1716                ".google.cloud.language.v2.EntityMention.Type",
1717            ))
1718        }
1719    }
1720}
1721
1722/// Represents a text span in the input document.
1723#[derive(Clone, Debug, Default, PartialEq)]
1724#[non_exhaustive]
1725pub struct TextSpan {
1726    /// The content of the text span, which is a substring of the document.
1727    pub content: std::string::String,
1728
1729    /// The API calculates the beginning offset of the content in the original
1730    /// document according to the
1731    /// [EncodingType][google.cloud.language.v2.EncodingType] specified in the API
1732    /// request.
1733    ///
1734    /// [google.cloud.language.v2.EncodingType]: crate::model::EncodingType
1735    pub begin_offset: i32,
1736
1737    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1738}
1739
1740impl TextSpan {
1741    pub fn new() -> Self {
1742        std::default::Default::default()
1743    }
1744
1745    /// Sets the value of [content][crate::model::TextSpan::content].
1746    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1747        self.content = v.into();
1748        self
1749    }
1750
1751    /// Sets the value of [begin_offset][crate::model::TextSpan::begin_offset].
1752    pub fn set_begin_offset<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
1753        self.begin_offset = v.into();
1754        self
1755    }
1756}
1757
1758impl wkt::message::Message for TextSpan {
1759    fn typename() -> &'static str {
1760        "type.googleapis.com/google.cloud.language.v2.TextSpan"
1761    }
1762}
1763
1764#[doc(hidden)]
1765impl<'de> serde::de::Deserialize<'de> for TextSpan {
1766    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1767    where
1768        D: serde::Deserializer<'de>,
1769    {
1770        #[allow(non_camel_case_types)]
1771        #[doc(hidden)]
1772        #[derive(PartialEq, Eq, Hash)]
1773        enum __FieldTag {
1774            __content,
1775            __begin_offset,
1776            Unknown(std::string::String),
1777        }
1778        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1779            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1780            where
1781                D: serde::Deserializer<'de>,
1782            {
1783                struct Visitor;
1784                impl<'de> serde::de::Visitor<'de> for Visitor {
1785                    type Value = __FieldTag;
1786                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1787                        formatter.write_str("a field name for TextSpan")
1788                    }
1789                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1790                    where
1791                        E: serde::de::Error,
1792                    {
1793                        use std::result::Result::Ok;
1794                        use std::string::ToString;
1795                        match value {
1796                            "content" => Ok(__FieldTag::__content),
1797                            "beginOffset" => Ok(__FieldTag::__begin_offset),
1798                            "begin_offset" => Ok(__FieldTag::__begin_offset),
1799                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1800                        }
1801                    }
1802                }
1803                deserializer.deserialize_identifier(Visitor)
1804            }
1805        }
1806        struct Visitor;
1807        impl<'de> serde::de::Visitor<'de> for Visitor {
1808            type Value = TextSpan;
1809            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1810                formatter.write_str("struct TextSpan")
1811            }
1812            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1813            where
1814                A: serde::de::MapAccess<'de>,
1815            {
1816                #[allow(unused_imports)]
1817                use serde::de::Error;
1818                use std::option::Option::Some;
1819                let mut fields = std::collections::HashSet::new();
1820                let mut result = Self::Value::new();
1821                while let Some(tag) = map.next_key::<__FieldTag>()? {
1822                    #[allow(clippy::match_single_binding)]
1823                    match tag {
1824                        __FieldTag::__content => {
1825                            if !fields.insert(__FieldTag::__content) {
1826                                return std::result::Result::Err(A::Error::duplicate_field(
1827                                    "multiple values for content",
1828                                ));
1829                            }
1830                            result.content = map
1831                                .next_value::<std::option::Option<std::string::String>>()?
1832                                .unwrap_or_default();
1833                        }
1834                        __FieldTag::__begin_offset => {
1835                            if !fields.insert(__FieldTag::__begin_offset) {
1836                                return std::result::Result::Err(A::Error::duplicate_field(
1837                                    "multiple values for begin_offset",
1838                                ));
1839                            }
1840                            struct __With(std::option::Option<i32>);
1841                            impl<'de> serde::de::Deserialize<'de> for __With {
1842                                fn deserialize<D>(
1843                                    deserializer: D,
1844                                ) -> std::result::Result<Self, D::Error>
1845                                where
1846                                    D: serde::de::Deserializer<'de>,
1847                                {
1848                                    serde_with::As::< std::option::Option<wkt::internal::I32> >::deserialize(deserializer).map(__With)
1849                                }
1850                            }
1851                            result.begin_offset = map.next_value::<__With>()?.0.unwrap_or_default();
1852                        }
1853                        __FieldTag::Unknown(key) => {
1854                            let value = map.next_value::<serde_json::Value>()?;
1855                            result._unknown_fields.insert(key, value);
1856                        }
1857                    }
1858                }
1859                std::result::Result::Ok(result)
1860            }
1861        }
1862        deserializer.deserialize_any(Visitor)
1863    }
1864}
1865
1866#[doc(hidden)]
1867impl serde::ser::Serialize for TextSpan {
1868    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1869    where
1870        S: serde::ser::Serializer,
1871    {
1872        use serde::ser::SerializeMap;
1873        #[allow(unused_imports)]
1874        use std::option::Option::Some;
1875        let mut state = serializer.serialize_map(std::option::Option::None)?;
1876        if !self.content.is_empty() {
1877            state.serialize_entry("content", &self.content)?;
1878        }
1879        if !wkt::internal::is_default(&self.begin_offset) {
1880            struct __With<'a>(&'a i32);
1881            impl<'a> serde::ser::Serialize for __With<'a> {
1882                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1883                where
1884                    S: serde::ser::Serializer,
1885                {
1886                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
1887                }
1888            }
1889            state.serialize_entry("beginOffset", &__With(&self.begin_offset))?;
1890        }
1891        if !self._unknown_fields.is_empty() {
1892            for (key, value) in self._unknown_fields.iter() {
1893                state.serialize_entry(key, &value)?;
1894            }
1895        }
1896        state.end()
1897    }
1898}
1899
1900/// Represents a category returned from the text classifier.
1901#[derive(Clone, Debug, Default, PartialEq)]
1902#[non_exhaustive]
1903pub struct ClassificationCategory {
1904    /// The name of the category representing the document.
1905    pub name: std::string::String,
1906
1907    /// The classifier's confidence of the category. Number represents how certain
1908    /// the classifier is that this category represents the given text.
1909    pub confidence: f32,
1910
1911    /// Optional. The classifier's severity of the category. This is only present
1912    /// when the ModerateTextRequest.ModelVersion is set to MODEL_VERSION_2, and
1913    /// the corresponding category has a severity score.
1914    pub severity: f32,
1915
1916    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1917}
1918
1919impl ClassificationCategory {
1920    pub fn new() -> Self {
1921        std::default::Default::default()
1922    }
1923
1924    /// Sets the value of [name][crate::model::ClassificationCategory::name].
1925    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1926        self.name = v.into();
1927        self
1928    }
1929
1930    /// Sets the value of [confidence][crate::model::ClassificationCategory::confidence].
1931    pub fn set_confidence<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1932        self.confidence = v.into();
1933        self
1934    }
1935
1936    /// Sets the value of [severity][crate::model::ClassificationCategory::severity].
1937    pub fn set_severity<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1938        self.severity = v.into();
1939        self
1940    }
1941}
1942
1943impl wkt::message::Message for ClassificationCategory {
1944    fn typename() -> &'static str {
1945        "type.googleapis.com/google.cloud.language.v2.ClassificationCategory"
1946    }
1947}
1948
1949#[doc(hidden)]
1950impl<'de> serde::de::Deserialize<'de> for ClassificationCategory {
1951    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1952    where
1953        D: serde::Deserializer<'de>,
1954    {
1955        #[allow(non_camel_case_types)]
1956        #[doc(hidden)]
1957        #[derive(PartialEq, Eq, Hash)]
1958        enum __FieldTag {
1959            __name,
1960            __confidence,
1961            __severity,
1962            Unknown(std::string::String),
1963        }
1964        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
1965            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1966            where
1967                D: serde::Deserializer<'de>,
1968            {
1969                struct Visitor;
1970                impl<'de> serde::de::Visitor<'de> for Visitor {
1971                    type Value = __FieldTag;
1972                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1973                        formatter.write_str("a field name for ClassificationCategory")
1974                    }
1975                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
1976                    where
1977                        E: serde::de::Error,
1978                    {
1979                        use std::result::Result::Ok;
1980                        use std::string::ToString;
1981                        match value {
1982                            "name" => Ok(__FieldTag::__name),
1983                            "confidence" => Ok(__FieldTag::__confidence),
1984                            "severity" => Ok(__FieldTag::__severity),
1985                            _ => Ok(__FieldTag::Unknown(value.to_string())),
1986                        }
1987                    }
1988                }
1989                deserializer.deserialize_identifier(Visitor)
1990            }
1991        }
1992        struct Visitor;
1993        impl<'de> serde::de::Visitor<'de> for Visitor {
1994            type Value = ClassificationCategory;
1995            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
1996                formatter.write_str("struct ClassificationCategory")
1997            }
1998            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
1999            where
2000                A: serde::de::MapAccess<'de>,
2001            {
2002                #[allow(unused_imports)]
2003                use serde::de::Error;
2004                use std::option::Option::Some;
2005                let mut fields = std::collections::HashSet::new();
2006                let mut result = Self::Value::new();
2007                while let Some(tag) = map.next_key::<__FieldTag>()? {
2008                    #[allow(clippy::match_single_binding)]
2009                    match tag {
2010                        __FieldTag::__name => {
2011                            if !fields.insert(__FieldTag::__name) {
2012                                return std::result::Result::Err(A::Error::duplicate_field(
2013                                    "multiple values for name",
2014                                ));
2015                            }
2016                            result.name = map
2017                                .next_value::<std::option::Option<std::string::String>>()?
2018                                .unwrap_or_default();
2019                        }
2020                        __FieldTag::__confidence => {
2021                            if !fields.insert(__FieldTag::__confidence) {
2022                                return std::result::Result::Err(A::Error::duplicate_field(
2023                                    "multiple values for confidence",
2024                                ));
2025                            }
2026                            struct __With(std::option::Option<f32>);
2027                            impl<'de> serde::de::Deserialize<'de> for __With {
2028                                fn deserialize<D>(
2029                                    deserializer: D,
2030                                ) -> std::result::Result<Self, D::Error>
2031                                where
2032                                    D: serde::de::Deserializer<'de>,
2033                                {
2034                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
2035                                }
2036                            }
2037                            result.confidence = map.next_value::<__With>()?.0.unwrap_or_default();
2038                        }
2039                        __FieldTag::__severity => {
2040                            if !fields.insert(__FieldTag::__severity) {
2041                                return std::result::Result::Err(A::Error::duplicate_field(
2042                                    "multiple values for severity",
2043                                ));
2044                            }
2045                            struct __With(std::option::Option<f32>);
2046                            impl<'de> serde::de::Deserialize<'de> for __With {
2047                                fn deserialize<D>(
2048                                    deserializer: D,
2049                                ) -> std::result::Result<Self, D::Error>
2050                                where
2051                                    D: serde::de::Deserializer<'de>,
2052                                {
2053                                    serde_with::As::< std::option::Option<wkt::internal::F32> >::deserialize(deserializer).map(__With)
2054                                }
2055                            }
2056                            result.severity = map.next_value::<__With>()?.0.unwrap_or_default();
2057                        }
2058                        __FieldTag::Unknown(key) => {
2059                            let value = map.next_value::<serde_json::Value>()?;
2060                            result._unknown_fields.insert(key, value);
2061                        }
2062                    }
2063                }
2064                std::result::Result::Ok(result)
2065            }
2066        }
2067        deserializer.deserialize_any(Visitor)
2068    }
2069}
2070
2071#[doc(hidden)]
2072impl serde::ser::Serialize for ClassificationCategory {
2073    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2074    where
2075        S: serde::ser::Serializer,
2076    {
2077        use serde::ser::SerializeMap;
2078        #[allow(unused_imports)]
2079        use std::option::Option::Some;
2080        let mut state = serializer.serialize_map(std::option::Option::None)?;
2081        if !self.name.is_empty() {
2082            state.serialize_entry("name", &self.name)?;
2083        }
2084        if !wkt::internal::is_default(&self.confidence) {
2085            struct __With<'a>(&'a f32);
2086            impl<'a> serde::ser::Serialize for __With<'a> {
2087                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2088                where
2089                    S: serde::ser::Serializer,
2090                {
2091                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
2092                }
2093            }
2094            state.serialize_entry("confidence", &__With(&self.confidence))?;
2095        }
2096        if !wkt::internal::is_default(&self.severity) {
2097            struct __With<'a>(&'a f32);
2098            impl<'a> serde::ser::Serialize for __With<'a> {
2099                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2100                where
2101                    S: serde::ser::Serializer,
2102                {
2103                    serde_with::As::<wkt::internal::F32>::serialize(self.0, serializer)
2104                }
2105            }
2106            state.serialize_entry("severity", &__With(&self.severity))?;
2107        }
2108        if !self._unknown_fields.is_empty() {
2109            for (key, value) in self._unknown_fields.iter() {
2110                state.serialize_entry(key, &value)?;
2111            }
2112        }
2113        state.end()
2114    }
2115}
2116
2117/// The sentiment analysis request message.
2118#[derive(Clone, Debug, Default, PartialEq)]
2119#[non_exhaustive]
2120pub struct AnalyzeSentimentRequest {
2121    /// Required. Input document.
2122    pub document: std::option::Option<crate::model::Document>,
2123
2124    /// The encoding type used by the API to calculate sentence offsets.
2125    pub encoding_type: crate::model::EncodingType,
2126
2127    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2128}
2129
2130impl AnalyzeSentimentRequest {
2131    pub fn new() -> Self {
2132        std::default::Default::default()
2133    }
2134
2135    /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
2136    pub fn set_document<T>(mut self, v: T) -> Self
2137    where
2138        T: std::convert::Into<crate::model::Document>,
2139    {
2140        self.document = std::option::Option::Some(v.into());
2141        self
2142    }
2143
2144    /// Sets or clears the value of [document][crate::model::AnalyzeSentimentRequest::document].
2145    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
2146    where
2147        T: std::convert::Into<crate::model::Document>,
2148    {
2149        self.document = v.map(|x| x.into());
2150        self
2151    }
2152
2153    /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
2154    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
2155        mut self,
2156        v: T,
2157    ) -> Self {
2158        self.encoding_type = v.into();
2159        self
2160    }
2161}
2162
2163impl wkt::message::Message for AnalyzeSentimentRequest {
2164    fn typename() -> &'static str {
2165        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentRequest"
2166    }
2167}
2168
2169#[doc(hidden)]
2170impl<'de> serde::de::Deserialize<'de> for AnalyzeSentimentRequest {
2171    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2172    where
2173        D: serde::Deserializer<'de>,
2174    {
2175        #[allow(non_camel_case_types)]
2176        #[doc(hidden)]
2177        #[derive(PartialEq, Eq, Hash)]
2178        enum __FieldTag {
2179            __document,
2180            __encoding_type,
2181            Unknown(std::string::String),
2182        }
2183        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2184            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2185            where
2186                D: serde::Deserializer<'de>,
2187            {
2188                struct Visitor;
2189                impl<'de> serde::de::Visitor<'de> for Visitor {
2190                    type Value = __FieldTag;
2191                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2192                        formatter.write_str("a field name for AnalyzeSentimentRequest")
2193                    }
2194                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2195                    where
2196                        E: serde::de::Error,
2197                    {
2198                        use std::result::Result::Ok;
2199                        use std::string::ToString;
2200                        match value {
2201                            "document" => Ok(__FieldTag::__document),
2202                            "encodingType" => Ok(__FieldTag::__encoding_type),
2203                            "encoding_type" => Ok(__FieldTag::__encoding_type),
2204                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2205                        }
2206                    }
2207                }
2208                deserializer.deserialize_identifier(Visitor)
2209            }
2210        }
2211        struct Visitor;
2212        impl<'de> serde::de::Visitor<'de> for Visitor {
2213            type Value = AnalyzeSentimentRequest;
2214            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2215                formatter.write_str("struct AnalyzeSentimentRequest")
2216            }
2217            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2218            where
2219                A: serde::de::MapAccess<'de>,
2220            {
2221                #[allow(unused_imports)]
2222                use serde::de::Error;
2223                use std::option::Option::Some;
2224                let mut fields = std::collections::HashSet::new();
2225                let mut result = Self::Value::new();
2226                while let Some(tag) = map.next_key::<__FieldTag>()? {
2227                    #[allow(clippy::match_single_binding)]
2228                    match tag {
2229                        __FieldTag::__document => {
2230                            if !fields.insert(__FieldTag::__document) {
2231                                return std::result::Result::Err(A::Error::duplicate_field(
2232                                    "multiple values for document",
2233                                ));
2234                            }
2235                            result.document =
2236                                map.next_value::<std::option::Option<crate::model::Document>>()?;
2237                        }
2238                        __FieldTag::__encoding_type => {
2239                            if !fields.insert(__FieldTag::__encoding_type) {
2240                                return std::result::Result::Err(A::Error::duplicate_field(
2241                                    "multiple values for encoding_type",
2242                                ));
2243                            }
2244                            result.encoding_type = map
2245                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
2246                                .unwrap_or_default();
2247                        }
2248                        __FieldTag::Unknown(key) => {
2249                            let value = map.next_value::<serde_json::Value>()?;
2250                            result._unknown_fields.insert(key, value);
2251                        }
2252                    }
2253                }
2254                std::result::Result::Ok(result)
2255            }
2256        }
2257        deserializer.deserialize_any(Visitor)
2258    }
2259}
2260
2261#[doc(hidden)]
2262impl serde::ser::Serialize for AnalyzeSentimentRequest {
2263    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2264    where
2265        S: serde::ser::Serializer,
2266    {
2267        use serde::ser::SerializeMap;
2268        #[allow(unused_imports)]
2269        use std::option::Option::Some;
2270        let mut state = serializer.serialize_map(std::option::Option::None)?;
2271        if self.document.is_some() {
2272            state.serialize_entry("document", &self.document)?;
2273        }
2274        if !wkt::internal::is_default(&self.encoding_type) {
2275            state.serialize_entry("encodingType", &self.encoding_type)?;
2276        }
2277        if !self._unknown_fields.is_empty() {
2278            for (key, value) in self._unknown_fields.iter() {
2279                state.serialize_entry(key, &value)?;
2280            }
2281        }
2282        state.end()
2283    }
2284}
2285
2286/// The sentiment analysis response message.
2287#[derive(Clone, Debug, Default, PartialEq)]
2288#[non_exhaustive]
2289pub struct AnalyzeSentimentResponse {
2290    /// The overall sentiment of the input document.
2291    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
2292
2293    /// The language of the text, which will be the same as the language specified
2294    /// in the request or, if not specified, the automatically-detected language.
2295    /// See [Document.language][] field for more details.
2296    pub language_code: std::string::String,
2297
2298    /// The sentiment for all the sentences in the document.
2299    pub sentences: std::vec::Vec<crate::model::Sentence>,
2300
2301    /// Whether the language is officially supported. The API may still return a
2302    /// response when the language is not supported, but it is on a best effort
2303    /// basis.
2304    pub language_supported: bool,
2305
2306    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2307}
2308
2309impl AnalyzeSentimentResponse {
2310    pub fn new() -> Self {
2311        std::default::Default::default()
2312    }
2313
2314    /// Sets the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
2315    pub fn set_document_sentiment<T>(mut self, v: T) -> Self
2316    where
2317        T: std::convert::Into<crate::model::Sentiment>,
2318    {
2319        self.document_sentiment = std::option::Option::Some(v.into());
2320        self
2321    }
2322
2323    /// Sets or clears the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
2324    pub fn set_or_clear_document_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
2325    where
2326        T: std::convert::Into<crate::model::Sentiment>,
2327    {
2328        self.document_sentiment = v.map(|x| x.into());
2329        self
2330    }
2331
2332    /// Sets the value of [language_code][crate::model::AnalyzeSentimentResponse::language_code].
2333    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
2334        self.language_code = v.into();
2335        self
2336    }
2337
2338    /// Sets the value of [sentences][crate::model::AnalyzeSentimentResponse::sentences].
2339    pub fn set_sentences<T, V>(mut self, v: T) -> Self
2340    where
2341        T: std::iter::IntoIterator<Item = V>,
2342        V: std::convert::Into<crate::model::Sentence>,
2343    {
2344        use std::iter::Iterator;
2345        self.sentences = v.into_iter().map(|i| i.into()).collect();
2346        self
2347    }
2348
2349    /// Sets the value of [language_supported][crate::model::AnalyzeSentimentResponse::language_supported].
2350    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
2351        self.language_supported = v.into();
2352        self
2353    }
2354}
2355
2356impl wkt::message::Message for AnalyzeSentimentResponse {
2357    fn typename() -> &'static str {
2358        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentResponse"
2359    }
2360}
2361
2362#[doc(hidden)]
2363impl<'de> serde::de::Deserialize<'de> for AnalyzeSentimentResponse {
2364    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2365    where
2366        D: serde::Deserializer<'de>,
2367    {
2368        #[allow(non_camel_case_types)]
2369        #[doc(hidden)]
2370        #[derive(PartialEq, Eq, Hash)]
2371        enum __FieldTag {
2372            __document_sentiment,
2373            __language_code,
2374            __sentences,
2375            __language_supported,
2376            Unknown(std::string::String),
2377        }
2378        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2379            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2380            where
2381                D: serde::Deserializer<'de>,
2382            {
2383                struct Visitor;
2384                impl<'de> serde::de::Visitor<'de> for Visitor {
2385                    type Value = __FieldTag;
2386                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2387                        formatter.write_str("a field name for AnalyzeSentimentResponse")
2388                    }
2389                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2390                    where
2391                        E: serde::de::Error,
2392                    {
2393                        use std::result::Result::Ok;
2394                        use std::string::ToString;
2395                        match value {
2396                            "documentSentiment" => Ok(__FieldTag::__document_sentiment),
2397                            "document_sentiment" => Ok(__FieldTag::__document_sentiment),
2398                            "languageCode" => Ok(__FieldTag::__language_code),
2399                            "language_code" => Ok(__FieldTag::__language_code),
2400                            "sentences" => Ok(__FieldTag::__sentences),
2401                            "languageSupported" => Ok(__FieldTag::__language_supported),
2402                            "language_supported" => Ok(__FieldTag::__language_supported),
2403                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2404                        }
2405                    }
2406                }
2407                deserializer.deserialize_identifier(Visitor)
2408            }
2409        }
2410        struct Visitor;
2411        impl<'de> serde::de::Visitor<'de> for Visitor {
2412            type Value = AnalyzeSentimentResponse;
2413            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2414                formatter.write_str("struct AnalyzeSentimentResponse")
2415            }
2416            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2417            where
2418                A: serde::de::MapAccess<'de>,
2419            {
2420                #[allow(unused_imports)]
2421                use serde::de::Error;
2422                use std::option::Option::Some;
2423                let mut fields = std::collections::HashSet::new();
2424                let mut result = Self::Value::new();
2425                while let Some(tag) = map.next_key::<__FieldTag>()? {
2426                    #[allow(clippy::match_single_binding)]
2427                    match tag {
2428                        __FieldTag::__document_sentiment => {
2429                            if !fields.insert(__FieldTag::__document_sentiment) {
2430                                return std::result::Result::Err(A::Error::duplicate_field(
2431                                    "multiple values for document_sentiment",
2432                                ));
2433                            }
2434                            result.document_sentiment =
2435                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
2436                        }
2437                        __FieldTag::__language_code => {
2438                            if !fields.insert(__FieldTag::__language_code) {
2439                                return std::result::Result::Err(A::Error::duplicate_field(
2440                                    "multiple values for language_code",
2441                                ));
2442                            }
2443                            result.language_code = map
2444                                .next_value::<std::option::Option<std::string::String>>()?
2445                                .unwrap_or_default();
2446                        }
2447                        __FieldTag::__sentences => {
2448                            if !fields.insert(__FieldTag::__sentences) {
2449                                return std::result::Result::Err(A::Error::duplicate_field(
2450                                    "multiple values for sentences",
2451                                ));
2452                            }
2453                            result.sentences = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Sentence>>>()?.unwrap_or_default();
2454                        }
2455                        __FieldTag::__language_supported => {
2456                            if !fields.insert(__FieldTag::__language_supported) {
2457                                return std::result::Result::Err(A::Error::duplicate_field(
2458                                    "multiple values for language_supported",
2459                                ));
2460                            }
2461                            result.language_supported = map
2462                                .next_value::<std::option::Option<bool>>()?
2463                                .unwrap_or_default();
2464                        }
2465                        __FieldTag::Unknown(key) => {
2466                            let value = map.next_value::<serde_json::Value>()?;
2467                            result._unknown_fields.insert(key, value);
2468                        }
2469                    }
2470                }
2471                std::result::Result::Ok(result)
2472            }
2473        }
2474        deserializer.deserialize_any(Visitor)
2475    }
2476}
2477
2478#[doc(hidden)]
2479impl serde::ser::Serialize for AnalyzeSentimentResponse {
2480    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2481    where
2482        S: serde::ser::Serializer,
2483    {
2484        use serde::ser::SerializeMap;
2485        #[allow(unused_imports)]
2486        use std::option::Option::Some;
2487        let mut state = serializer.serialize_map(std::option::Option::None)?;
2488        if self.document_sentiment.is_some() {
2489            state.serialize_entry("documentSentiment", &self.document_sentiment)?;
2490        }
2491        if !self.language_code.is_empty() {
2492            state.serialize_entry("languageCode", &self.language_code)?;
2493        }
2494        if !self.sentences.is_empty() {
2495            state.serialize_entry("sentences", &self.sentences)?;
2496        }
2497        if !wkt::internal::is_default(&self.language_supported) {
2498            state.serialize_entry("languageSupported", &self.language_supported)?;
2499        }
2500        if !self._unknown_fields.is_empty() {
2501            for (key, value) in self._unknown_fields.iter() {
2502                state.serialize_entry(key, &value)?;
2503            }
2504        }
2505        state.end()
2506    }
2507}
2508
2509/// The entity analysis request message.
2510#[derive(Clone, Debug, Default, PartialEq)]
2511#[non_exhaustive]
2512pub struct AnalyzeEntitiesRequest {
2513    /// Required. Input document.
2514    pub document: std::option::Option<crate::model::Document>,
2515
2516    /// The encoding type used by the API to calculate offsets.
2517    pub encoding_type: crate::model::EncodingType,
2518
2519    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2520}
2521
2522impl AnalyzeEntitiesRequest {
2523    pub fn new() -> Self {
2524        std::default::Default::default()
2525    }
2526
2527    /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
2528    pub fn set_document<T>(mut self, v: T) -> Self
2529    where
2530        T: std::convert::Into<crate::model::Document>,
2531    {
2532        self.document = std::option::Option::Some(v.into());
2533        self
2534    }
2535
2536    /// Sets or clears the value of [document][crate::model::AnalyzeEntitiesRequest::document].
2537    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
2538    where
2539        T: std::convert::Into<crate::model::Document>,
2540    {
2541        self.document = v.map(|x| x.into());
2542        self
2543    }
2544
2545    /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
2546    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
2547        mut self,
2548        v: T,
2549    ) -> Self {
2550        self.encoding_type = v.into();
2551        self
2552    }
2553}
2554
2555impl wkt::message::Message for AnalyzeEntitiesRequest {
2556    fn typename() -> &'static str {
2557        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesRequest"
2558    }
2559}
2560
2561#[doc(hidden)]
2562impl<'de> serde::de::Deserialize<'de> for AnalyzeEntitiesRequest {
2563    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2564    where
2565        D: serde::Deserializer<'de>,
2566    {
2567        #[allow(non_camel_case_types)]
2568        #[doc(hidden)]
2569        #[derive(PartialEq, Eq, Hash)]
2570        enum __FieldTag {
2571            __document,
2572            __encoding_type,
2573            Unknown(std::string::String),
2574        }
2575        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2576            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2577            where
2578                D: serde::Deserializer<'de>,
2579            {
2580                struct Visitor;
2581                impl<'de> serde::de::Visitor<'de> for Visitor {
2582                    type Value = __FieldTag;
2583                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2584                        formatter.write_str("a field name for AnalyzeEntitiesRequest")
2585                    }
2586                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2587                    where
2588                        E: serde::de::Error,
2589                    {
2590                        use std::result::Result::Ok;
2591                        use std::string::ToString;
2592                        match value {
2593                            "document" => Ok(__FieldTag::__document),
2594                            "encodingType" => Ok(__FieldTag::__encoding_type),
2595                            "encoding_type" => Ok(__FieldTag::__encoding_type),
2596                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2597                        }
2598                    }
2599                }
2600                deserializer.deserialize_identifier(Visitor)
2601            }
2602        }
2603        struct Visitor;
2604        impl<'de> serde::de::Visitor<'de> for Visitor {
2605            type Value = AnalyzeEntitiesRequest;
2606            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2607                formatter.write_str("struct AnalyzeEntitiesRequest")
2608            }
2609            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2610            where
2611                A: serde::de::MapAccess<'de>,
2612            {
2613                #[allow(unused_imports)]
2614                use serde::de::Error;
2615                use std::option::Option::Some;
2616                let mut fields = std::collections::HashSet::new();
2617                let mut result = Self::Value::new();
2618                while let Some(tag) = map.next_key::<__FieldTag>()? {
2619                    #[allow(clippy::match_single_binding)]
2620                    match tag {
2621                        __FieldTag::__document => {
2622                            if !fields.insert(__FieldTag::__document) {
2623                                return std::result::Result::Err(A::Error::duplicate_field(
2624                                    "multiple values for document",
2625                                ));
2626                            }
2627                            result.document =
2628                                map.next_value::<std::option::Option<crate::model::Document>>()?;
2629                        }
2630                        __FieldTag::__encoding_type => {
2631                            if !fields.insert(__FieldTag::__encoding_type) {
2632                                return std::result::Result::Err(A::Error::duplicate_field(
2633                                    "multiple values for encoding_type",
2634                                ));
2635                            }
2636                            result.encoding_type = map
2637                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
2638                                .unwrap_or_default();
2639                        }
2640                        __FieldTag::Unknown(key) => {
2641                            let value = map.next_value::<serde_json::Value>()?;
2642                            result._unknown_fields.insert(key, value);
2643                        }
2644                    }
2645                }
2646                std::result::Result::Ok(result)
2647            }
2648        }
2649        deserializer.deserialize_any(Visitor)
2650    }
2651}
2652
2653#[doc(hidden)]
2654impl serde::ser::Serialize for AnalyzeEntitiesRequest {
2655    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2656    where
2657        S: serde::ser::Serializer,
2658    {
2659        use serde::ser::SerializeMap;
2660        #[allow(unused_imports)]
2661        use std::option::Option::Some;
2662        let mut state = serializer.serialize_map(std::option::Option::None)?;
2663        if self.document.is_some() {
2664            state.serialize_entry("document", &self.document)?;
2665        }
2666        if !wkt::internal::is_default(&self.encoding_type) {
2667            state.serialize_entry("encodingType", &self.encoding_type)?;
2668        }
2669        if !self._unknown_fields.is_empty() {
2670            for (key, value) in self._unknown_fields.iter() {
2671                state.serialize_entry(key, &value)?;
2672            }
2673        }
2674        state.end()
2675    }
2676}
2677
2678/// The entity analysis response message.
2679#[derive(Clone, Debug, Default, PartialEq)]
2680#[non_exhaustive]
2681pub struct AnalyzeEntitiesResponse {
2682    /// The recognized entities in the input document.
2683    pub entities: std::vec::Vec<crate::model::Entity>,
2684
2685    /// The language of the text, which will be the same as the language specified
2686    /// in the request or, if not specified, the automatically-detected language.
2687    /// See [Document.language][] field for more details.
2688    pub language_code: std::string::String,
2689
2690    /// Whether the language is officially supported. The API may still return a
2691    /// response when the language is not supported, but it is on a best effort
2692    /// basis.
2693    pub language_supported: bool,
2694
2695    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2696}
2697
2698impl AnalyzeEntitiesResponse {
2699    pub fn new() -> Self {
2700        std::default::Default::default()
2701    }
2702
2703    /// Sets the value of [entities][crate::model::AnalyzeEntitiesResponse::entities].
2704    pub fn set_entities<T, V>(mut self, v: T) -> Self
2705    where
2706        T: std::iter::IntoIterator<Item = V>,
2707        V: std::convert::Into<crate::model::Entity>,
2708    {
2709        use std::iter::Iterator;
2710        self.entities = v.into_iter().map(|i| i.into()).collect();
2711        self
2712    }
2713
2714    /// Sets the value of [language_code][crate::model::AnalyzeEntitiesResponse::language_code].
2715    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
2716        self.language_code = v.into();
2717        self
2718    }
2719
2720    /// Sets the value of [language_supported][crate::model::AnalyzeEntitiesResponse::language_supported].
2721    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
2722        self.language_supported = v.into();
2723        self
2724    }
2725}
2726
2727impl wkt::message::Message for AnalyzeEntitiesResponse {
2728    fn typename() -> &'static str {
2729        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesResponse"
2730    }
2731}
2732
2733#[doc(hidden)]
2734impl<'de> serde::de::Deserialize<'de> for AnalyzeEntitiesResponse {
2735    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2736    where
2737        D: serde::Deserializer<'de>,
2738    {
2739        #[allow(non_camel_case_types)]
2740        #[doc(hidden)]
2741        #[derive(PartialEq, Eq, Hash)]
2742        enum __FieldTag {
2743            __entities,
2744            __language_code,
2745            __language_supported,
2746            Unknown(std::string::String),
2747        }
2748        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2749            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2750            where
2751                D: serde::Deserializer<'de>,
2752            {
2753                struct Visitor;
2754                impl<'de> serde::de::Visitor<'de> for Visitor {
2755                    type Value = __FieldTag;
2756                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2757                        formatter.write_str("a field name for AnalyzeEntitiesResponse")
2758                    }
2759                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2760                    where
2761                        E: serde::de::Error,
2762                    {
2763                        use std::result::Result::Ok;
2764                        use std::string::ToString;
2765                        match value {
2766                            "entities" => Ok(__FieldTag::__entities),
2767                            "languageCode" => Ok(__FieldTag::__language_code),
2768                            "language_code" => Ok(__FieldTag::__language_code),
2769                            "languageSupported" => Ok(__FieldTag::__language_supported),
2770                            "language_supported" => Ok(__FieldTag::__language_supported),
2771                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2772                        }
2773                    }
2774                }
2775                deserializer.deserialize_identifier(Visitor)
2776            }
2777        }
2778        struct Visitor;
2779        impl<'de> serde::de::Visitor<'de> for Visitor {
2780            type Value = AnalyzeEntitiesResponse;
2781            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2782                formatter.write_str("struct AnalyzeEntitiesResponse")
2783            }
2784            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2785            where
2786                A: serde::de::MapAccess<'de>,
2787            {
2788                #[allow(unused_imports)]
2789                use serde::de::Error;
2790                use std::option::Option::Some;
2791                let mut fields = std::collections::HashSet::new();
2792                let mut result = Self::Value::new();
2793                while let Some(tag) = map.next_key::<__FieldTag>()? {
2794                    #[allow(clippy::match_single_binding)]
2795                    match tag {
2796                        __FieldTag::__entities => {
2797                            if !fields.insert(__FieldTag::__entities) {
2798                                return std::result::Result::Err(A::Error::duplicate_field(
2799                                    "multiple values for entities",
2800                                ));
2801                            }
2802                            result.entities = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Entity>>>()?.unwrap_or_default();
2803                        }
2804                        __FieldTag::__language_code => {
2805                            if !fields.insert(__FieldTag::__language_code) {
2806                                return std::result::Result::Err(A::Error::duplicate_field(
2807                                    "multiple values for language_code",
2808                                ));
2809                            }
2810                            result.language_code = map
2811                                .next_value::<std::option::Option<std::string::String>>()?
2812                                .unwrap_or_default();
2813                        }
2814                        __FieldTag::__language_supported => {
2815                            if !fields.insert(__FieldTag::__language_supported) {
2816                                return std::result::Result::Err(A::Error::duplicate_field(
2817                                    "multiple values for language_supported",
2818                                ));
2819                            }
2820                            result.language_supported = map
2821                                .next_value::<std::option::Option<bool>>()?
2822                                .unwrap_or_default();
2823                        }
2824                        __FieldTag::Unknown(key) => {
2825                            let value = map.next_value::<serde_json::Value>()?;
2826                            result._unknown_fields.insert(key, value);
2827                        }
2828                    }
2829                }
2830                std::result::Result::Ok(result)
2831            }
2832        }
2833        deserializer.deserialize_any(Visitor)
2834    }
2835}
2836
2837#[doc(hidden)]
2838impl serde::ser::Serialize for AnalyzeEntitiesResponse {
2839    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2840    where
2841        S: serde::ser::Serializer,
2842    {
2843        use serde::ser::SerializeMap;
2844        #[allow(unused_imports)]
2845        use std::option::Option::Some;
2846        let mut state = serializer.serialize_map(std::option::Option::None)?;
2847        if !self.entities.is_empty() {
2848            state.serialize_entry("entities", &self.entities)?;
2849        }
2850        if !self.language_code.is_empty() {
2851            state.serialize_entry("languageCode", &self.language_code)?;
2852        }
2853        if !wkt::internal::is_default(&self.language_supported) {
2854            state.serialize_entry("languageSupported", &self.language_supported)?;
2855        }
2856        if !self._unknown_fields.is_empty() {
2857            for (key, value) in self._unknown_fields.iter() {
2858                state.serialize_entry(key, &value)?;
2859            }
2860        }
2861        state.end()
2862    }
2863}
2864
2865/// The document classification request message.
2866#[derive(Clone, Debug, Default, PartialEq)]
2867#[non_exhaustive]
2868pub struct ClassifyTextRequest {
2869    /// Required. Input document.
2870    pub document: std::option::Option<crate::model::Document>,
2871
2872    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
2873}
2874
2875impl ClassifyTextRequest {
2876    pub fn new() -> Self {
2877        std::default::Default::default()
2878    }
2879
2880    /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
2881    pub fn set_document<T>(mut self, v: T) -> Self
2882    where
2883        T: std::convert::Into<crate::model::Document>,
2884    {
2885        self.document = std::option::Option::Some(v.into());
2886        self
2887    }
2888
2889    /// Sets or clears the value of [document][crate::model::ClassifyTextRequest::document].
2890    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
2891    where
2892        T: std::convert::Into<crate::model::Document>,
2893    {
2894        self.document = v.map(|x| x.into());
2895        self
2896    }
2897}
2898
2899impl wkt::message::Message for ClassifyTextRequest {
2900    fn typename() -> &'static str {
2901        "type.googleapis.com/google.cloud.language.v2.ClassifyTextRequest"
2902    }
2903}
2904
2905#[doc(hidden)]
2906impl<'de> serde::de::Deserialize<'de> for ClassifyTextRequest {
2907    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2908    where
2909        D: serde::Deserializer<'de>,
2910    {
2911        #[allow(non_camel_case_types)]
2912        #[doc(hidden)]
2913        #[derive(PartialEq, Eq, Hash)]
2914        enum __FieldTag {
2915            __document,
2916            Unknown(std::string::String),
2917        }
2918        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
2919            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2920            where
2921                D: serde::Deserializer<'de>,
2922            {
2923                struct Visitor;
2924                impl<'de> serde::de::Visitor<'de> for Visitor {
2925                    type Value = __FieldTag;
2926                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2927                        formatter.write_str("a field name for ClassifyTextRequest")
2928                    }
2929                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
2930                    where
2931                        E: serde::de::Error,
2932                    {
2933                        use std::result::Result::Ok;
2934                        use std::string::ToString;
2935                        match value {
2936                            "document" => Ok(__FieldTag::__document),
2937                            _ => Ok(__FieldTag::Unknown(value.to_string())),
2938                        }
2939                    }
2940                }
2941                deserializer.deserialize_identifier(Visitor)
2942            }
2943        }
2944        struct Visitor;
2945        impl<'de> serde::de::Visitor<'de> for Visitor {
2946            type Value = ClassifyTextRequest;
2947            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
2948                formatter.write_str("struct ClassifyTextRequest")
2949            }
2950            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
2951            where
2952                A: serde::de::MapAccess<'de>,
2953            {
2954                #[allow(unused_imports)]
2955                use serde::de::Error;
2956                use std::option::Option::Some;
2957                let mut fields = std::collections::HashSet::new();
2958                let mut result = Self::Value::new();
2959                while let Some(tag) = map.next_key::<__FieldTag>()? {
2960                    #[allow(clippy::match_single_binding)]
2961                    match tag {
2962                        __FieldTag::__document => {
2963                            if !fields.insert(__FieldTag::__document) {
2964                                return std::result::Result::Err(A::Error::duplicate_field(
2965                                    "multiple values for document",
2966                                ));
2967                            }
2968                            result.document =
2969                                map.next_value::<std::option::Option<crate::model::Document>>()?;
2970                        }
2971                        __FieldTag::Unknown(key) => {
2972                            let value = map.next_value::<serde_json::Value>()?;
2973                            result._unknown_fields.insert(key, value);
2974                        }
2975                    }
2976                }
2977                std::result::Result::Ok(result)
2978            }
2979        }
2980        deserializer.deserialize_any(Visitor)
2981    }
2982}
2983
2984#[doc(hidden)]
2985impl serde::ser::Serialize for ClassifyTextRequest {
2986    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2987    where
2988        S: serde::ser::Serializer,
2989    {
2990        use serde::ser::SerializeMap;
2991        #[allow(unused_imports)]
2992        use std::option::Option::Some;
2993        let mut state = serializer.serialize_map(std::option::Option::None)?;
2994        if self.document.is_some() {
2995            state.serialize_entry("document", &self.document)?;
2996        }
2997        if !self._unknown_fields.is_empty() {
2998            for (key, value) in self._unknown_fields.iter() {
2999                state.serialize_entry(key, &value)?;
3000            }
3001        }
3002        state.end()
3003    }
3004}
3005
3006/// The document classification response message.
3007#[derive(Clone, Debug, Default, PartialEq)]
3008#[non_exhaustive]
3009pub struct ClassifyTextResponse {
3010    /// Categories representing the input document.
3011    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
3012
3013    /// The language of the text, which will be the same as the language specified
3014    /// in the request or, if not specified, the automatically-detected language.
3015    /// See [Document.language][] field for more details.
3016    pub language_code: std::string::String,
3017
3018    /// Whether the language is officially supported. The API may still return a
3019    /// response when the language is not supported, but it is on a best effort
3020    /// basis.
3021    pub language_supported: bool,
3022
3023    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3024}
3025
3026impl ClassifyTextResponse {
3027    pub fn new() -> Self {
3028        std::default::Default::default()
3029    }
3030
3031    /// Sets the value of [categories][crate::model::ClassifyTextResponse::categories].
3032    pub fn set_categories<T, V>(mut self, v: T) -> Self
3033    where
3034        T: std::iter::IntoIterator<Item = V>,
3035        V: std::convert::Into<crate::model::ClassificationCategory>,
3036    {
3037        use std::iter::Iterator;
3038        self.categories = v.into_iter().map(|i| i.into()).collect();
3039        self
3040    }
3041
3042    /// Sets the value of [language_code][crate::model::ClassifyTextResponse::language_code].
3043    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
3044        self.language_code = v.into();
3045        self
3046    }
3047
3048    /// Sets the value of [language_supported][crate::model::ClassifyTextResponse::language_supported].
3049    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3050        self.language_supported = v.into();
3051        self
3052    }
3053}
3054
3055impl wkt::message::Message for ClassifyTextResponse {
3056    fn typename() -> &'static str {
3057        "type.googleapis.com/google.cloud.language.v2.ClassifyTextResponse"
3058    }
3059}
3060
3061#[doc(hidden)]
3062impl<'de> serde::de::Deserialize<'de> for ClassifyTextResponse {
3063    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3064    where
3065        D: serde::Deserializer<'de>,
3066    {
3067        #[allow(non_camel_case_types)]
3068        #[doc(hidden)]
3069        #[derive(PartialEq, Eq, Hash)]
3070        enum __FieldTag {
3071            __categories,
3072            __language_code,
3073            __language_supported,
3074            Unknown(std::string::String),
3075        }
3076        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3077            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3078            where
3079                D: serde::Deserializer<'de>,
3080            {
3081                struct Visitor;
3082                impl<'de> serde::de::Visitor<'de> for Visitor {
3083                    type Value = __FieldTag;
3084                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3085                        formatter.write_str("a field name for ClassifyTextResponse")
3086                    }
3087                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3088                    where
3089                        E: serde::de::Error,
3090                    {
3091                        use std::result::Result::Ok;
3092                        use std::string::ToString;
3093                        match value {
3094                            "categories" => Ok(__FieldTag::__categories),
3095                            "languageCode" => Ok(__FieldTag::__language_code),
3096                            "language_code" => Ok(__FieldTag::__language_code),
3097                            "languageSupported" => Ok(__FieldTag::__language_supported),
3098                            "language_supported" => Ok(__FieldTag::__language_supported),
3099                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3100                        }
3101                    }
3102                }
3103                deserializer.deserialize_identifier(Visitor)
3104            }
3105        }
3106        struct Visitor;
3107        impl<'de> serde::de::Visitor<'de> for Visitor {
3108            type Value = ClassifyTextResponse;
3109            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3110                formatter.write_str("struct ClassifyTextResponse")
3111            }
3112            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3113            where
3114                A: serde::de::MapAccess<'de>,
3115            {
3116                #[allow(unused_imports)]
3117                use serde::de::Error;
3118                use std::option::Option::Some;
3119                let mut fields = std::collections::HashSet::new();
3120                let mut result = Self::Value::new();
3121                while let Some(tag) = map.next_key::<__FieldTag>()? {
3122                    #[allow(clippy::match_single_binding)]
3123                    match tag {
3124                        __FieldTag::__categories => {
3125                            if !fields.insert(__FieldTag::__categories) {
3126                                return std::result::Result::Err(A::Error::duplicate_field(
3127                                    "multiple values for categories",
3128                                ));
3129                            }
3130                            result.categories = map
3131                                .next_value::<std::option::Option<
3132                                    std::vec::Vec<crate::model::ClassificationCategory>,
3133                                >>()?
3134                                .unwrap_or_default();
3135                        }
3136                        __FieldTag::__language_code => {
3137                            if !fields.insert(__FieldTag::__language_code) {
3138                                return std::result::Result::Err(A::Error::duplicate_field(
3139                                    "multiple values for language_code",
3140                                ));
3141                            }
3142                            result.language_code = map
3143                                .next_value::<std::option::Option<std::string::String>>()?
3144                                .unwrap_or_default();
3145                        }
3146                        __FieldTag::__language_supported => {
3147                            if !fields.insert(__FieldTag::__language_supported) {
3148                                return std::result::Result::Err(A::Error::duplicate_field(
3149                                    "multiple values for language_supported",
3150                                ));
3151                            }
3152                            result.language_supported = map
3153                                .next_value::<std::option::Option<bool>>()?
3154                                .unwrap_or_default();
3155                        }
3156                        __FieldTag::Unknown(key) => {
3157                            let value = map.next_value::<serde_json::Value>()?;
3158                            result._unknown_fields.insert(key, value);
3159                        }
3160                    }
3161                }
3162                std::result::Result::Ok(result)
3163            }
3164        }
3165        deserializer.deserialize_any(Visitor)
3166    }
3167}
3168
3169#[doc(hidden)]
3170impl serde::ser::Serialize for ClassifyTextResponse {
3171    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3172    where
3173        S: serde::ser::Serializer,
3174    {
3175        use serde::ser::SerializeMap;
3176        #[allow(unused_imports)]
3177        use std::option::Option::Some;
3178        let mut state = serializer.serialize_map(std::option::Option::None)?;
3179        if !self.categories.is_empty() {
3180            state.serialize_entry("categories", &self.categories)?;
3181        }
3182        if !self.language_code.is_empty() {
3183            state.serialize_entry("languageCode", &self.language_code)?;
3184        }
3185        if !wkt::internal::is_default(&self.language_supported) {
3186            state.serialize_entry("languageSupported", &self.language_supported)?;
3187        }
3188        if !self._unknown_fields.is_empty() {
3189            for (key, value) in self._unknown_fields.iter() {
3190                state.serialize_entry(key, &value)?;
3191            }
3192        }
3193        state.end()
3194    }
3195}
3196
3197/// The document moderation request message.
3198#[derive(Clone, Debug, Default, PartialEq)]
3199#[non_exhaustive]
3200pub struct ModerateTextRequest {
3201    /// Required. Input document.
3202    pub document: std::option::Option<crate::model::Document>,
3203
3204    /// Optional. The model version to use for ModerateText.
3205    pub model_version: crate::model::moderate_text_request::ModelVersion,
3206
3207    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3208}
3209
3210impl ModerateTextRequest {
3211    pub fn new() -> Self {
3212        std::default::Default::default()
3213    }
3214
3215    /// Sets the value of [document][crate::model::ModerateTextRequest::document].
3216    pub fn set_document<T>(mut self, v: T) -> Self
3217    where
3218        T: std::convert::Into<crate::model::Document>,
3219    {
3220        self.document = std::option::Option::Some(v.into());
3221        self
3222    }
3223
3224    /// Sets or clears the value of [document][crate::model::ModerateTextRequest::document].
3225    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
3226    where
3227        T: std::convert::Into<crate::model::Document>,
3228    {
3229        self.document = v.map(|x| x.into());
3230        self
3231    }
3232
3233    /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
3234    pub fn set_model_version<
3235        T: std::convert::Into<crate::model::moderate_text_request::ModelVersion>,
3236    >(
3237        mut self,
3238        v: T,
3239    ) -> Self {
3240        self.model_version = v.into();
3241        self
3242    }
3243}
3244
3245impl wkt::message::Message for ModerateTextRequest {
3246    fn typename() -> &'static str {
3247        "type.googleapis.com/google.cloud.language.v2.ModerateTextRequest"
3248    }
3249}
3250
3251#[doc(hidden)]
3252impl<'de> serde::de::Deserialize<'de> for ModerateTextRequest {
3253    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3254    where
3255        D: serde::Deserializer<'de>,
3256    {
3257        #[allow(non_camel_case_types)]
3258        #[doc(hidden)]
3259        #[derive(PartialEq, Eq, Hash)]
3260        enum __FieldTag {
3261            __document,
3262            __model_version,
3263            Unknown(std::string::String),
3264        }
3265        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3266            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3267            where
3268                D: serde::Deserializer<'de>,
3269            {
3270                struct Visitor;
3271                impl<'de> serde::de::Visitor<'de> for Visitor {
3272                    type Value = __FieldTag;
3273                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3274                        formatter.write_str("a field name for ModerateTextRequest")
3275                    }
3276                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3277                    where
3278                        E: serde::de::Error,
3279                    {
3280                        use std::result::Result::Ok;
3281                        use std::string::ToString;
3282                        match value {
3283                            "document" => Ok(__FieldTag::__document),
3284                            "modelVersion" => Ok(__FieldTag::__model_version),
3285                            "model_version" => Ok(__FieldTag::__model_version),
3286                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3287                        }
3288                    }
3289                }
3290                deserializer.deserialize_identifier(Visitor)
3291            }
3292        }
3293        struct Visitor;
3294        impl<'de> serde::de::Visitor<'de> for Visitor {
3295            type Value = ModerateTextRequest;
3296            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3297                formatter.write_str("struct ModerateTextRequest")
3298            }
3299            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3300            where
3301                A: serde::de::MapAccess<'de>,
3302            {
3303                #[allow(unused_imports)]
3304                use serde::de::Error;
3305                use std::option::Option::Some;
3306                let mut fields = std::collections::HashSet::new();
3307                let mut result = Self::Value::new();
3308                while let Some(tag) = map.next_key::<__FieldTag>()? {
3309                    #[allow(clippy::match_single_binding)]
3310                    match tag {
3311                        __FieldTag::__document => {
3312                            if !fields.insert(__FieldTag::__document) {
3313                                return std::result::Result::Err(A::Error::duplicate_field(
3314                                    "multiple values for document",
3315                                ));
3316                            }
3317                            result.document =
3318                                map.next_value::<std::option::Option<crate::model::Document>>()?;
3319                        }
3320                        __FieldTag::__model_version => {
3321                            if !fields.insert(__FieldTag::__model_version) {
3322                                return std::result::Result::Err(A::Error::duplicate_field(
3323                                    "multiple values for model_version",
3324                                ));
3325                            }
3326                            result.model_version = map
3327                                .next_value::<std::option::Option<
3328                                    crate::model::moderate_text_request::ModelVersion,
3329                                >>()?
3330                                .unwrap_or_default();
3331                        }
3332                        __FieldTag::Unknown(key) => {
3333                            let value = map.next_value::<serde_json::Value>()?;
3334                            result._unknown_fields.insert(key, value);
3335                        }
3336                    }
3337                }
3338                std::result::Result::Ok(result)
3339            }
3340        }
3341        deserializer.deserialize_any(Visitor)
3342    }
3343}
3344
3345#[doc(hidden)]
3346impl serde::ser::Serialize for ModerateTextRequest {
3347    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3348    where
3349        S: serde::ser::Serializer,
3350    {
3351        use serde::ser::SerializeMap;
3352        #[allow(unused_imports)]
3353        use std::option::Option::Some;
3354        let mut state = serializer.serialize_map(std::option::Option::None)?;
3355        if self.document.is_some() {
3356            state.serialize_entry("document", &self.document)?;
3357        }
3358        if !wkt::internal::is_default(&self.model_version) {
3359            state.serialize_entry("modelVersion", &self.model_version)?;
3360        }
3361        if !self._unknown_fields.is_empty() {
3362            for (key, value) in self._unknown_fields.iter() {
3363                state.serialize_entry(key, &value)?;
3364            }
3365        }
3366        state.end()
3367    }
3368}
3369
3370/// Defines additional types related to [ModerateTextRequest].
3371pub mod moderate_text_request {
3372    #[allow(unused_imports)]
3373    use super::*;
3374
3375    /// The model version to use for ModerateText.
3376    ///
3377    /// # Working with unknown values
3378    ///
3379    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
3380    /// additional enum variants at any time. Adding new variants is not considered
3381    /// a breaking change. Applications should write their code in anticipation of:
3382    ///
3383    /// - New values appearing in future releases of the client library, **and**
3384    /// - New values received dynamically, without application changes.
3385    ///
3386    /// Please consult the [Working with enums] section in the user guide for some
3387    /// guidelines.
3388    ///
3389    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
3390    #[derive(Clone, Debug, PartialEq)]
3391    #[non_exhaustive]
3392    pub enum ModelVersion {
3393        /// The default model version.
3394        Unspecified,
3395        /// Use the v1 model, this model is used by default when not provided.
3396        /// The v1 model only returns probability (confidence) score for each
3397        /// category.
3398        ModelVersion1,
3399        /// Use the v2 model.
3400        /// The v2 model only returns probability (confidence) score for each
3401        /// category, and returns severity score for a subset of the categories.
3402        ModelVersion2,
3403        /// If set, the enum was initialized with an unknown value.
3404        ///
3405        /// Applications can examine the value using [ModelVersion::value] or
3406        /// [ModelVersion::name].
3407        UnknownValue(model_version::UnknownValue),
3408    }
3409
3410    #[doc(hidden)]
3411    pub mod model_version {
3412        #[allow(unused_imports)]
3413        use super::*;
3414        #[derive(Clone, Debug, PartialEq)]
3415        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
3416    }
3417
3418    impl ModelVersion {
3419        /// Gets the enum value.
3420        ///
3421        /// Returns `None` if the enum contains an unknown value deserialized from
3422        /// the string representation of enums.
3423        pub fn value(&self) -> std::option::Option<i32> {
3424            match self {
3425                Self::Unspecified => std::option::Option::Some(0),
3426                Self::ModelVersion1 => std::option::Option::Some(1),
3427                Self::ModelVersion2 => std::option::Option::Some(2),
3428                Self::UnknownValue(u) => u.0.value(),
3429            }
3430        }
3431
3432        /// Gets the enum value as a string.
3433        ///
3434        /// Returns `None` if the enum contains an unknown value deserialized from
3435        /// the integer representation of enums.
3436        pub fn name(&self) -> std::option::Option<&str> {
3437            match self {
3438                Self::Unspecified => std::option::Option::Some("MODEL_VERSION_UNSPECIFIED"),
3439                Self::ModelVersion1 => std::option::Option::Some("MODEL_VERSION_1"),
3440                Self::ModelVersion2 => std::option::Option::Some("MODEL_VERSION_2"),
3441                Self::UnknownValue(u) => u.0.name(),
3442            }
3443        }
3444    }
3445
3446    impl std::default::Default for ModelVersion {
3447        fn default() -> Self {
3448            use std::convert::From;
3449            Self::from(0)
3450        }
3451    }
3452
3453    impl std::fmt::Display for ModelVersion {
3454        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
3455            wkt::internal::display_enum(f, self.name(), self.value())
3456        }
3457    }
3458
3459    impl std::convert::From<i32> for ModelVersion {
3460        fn from(value: i32) -> Self {
3461            match value {
3462                0 => Self::Unspecified,
3463                1 => Self::ModelVersion1,
3464                2 => Self::ModelVersion2,
3465                _ => Self::UnknownValue(model_version::UnknownValue(
3466                    wkt::internal::UnknownEnumValue::Integer(value),
3467                )),
3468            }
3469        }
3470    }
3471
3472    impl std::convert::From<&str> for ModelVersion {
3473        fn from(value: &str) -> Self {
3474            use std::string::ToString;
3475            match value {
3476                "MODEL_VERSION_UNSPECIFIED" => Self::Unspecified,
3477                "MODEL_VERSION_1" => Self::ModelVersion1,
3478                "MODEL_VERSION_2" => Self::ModelVersion2,
3479                _ => Self::UnknownValue(model_version::UnknownValue(
3480                    wkt::internal::UnknownEnumValue::String(value.to_string()),
3481                )),
3482            }
3483        }
3484    }
3485
3486    impl serde::ser::Serialize for ModelVersion {
3487        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3488        where
3489            S: serde::Serializer,
3490        {
3491            match self {
3492                Self::Unspecified => serializer.serialize_i32(0),
3493                Self::ModelVersion1 => serializer.serialize_i32(1),
3494                Self::ModelVersion2 => serializer.serialize_i32(2),
3495                Self::UnknownValue(u) => u.0.serialize(serializer),
3496            }
3497        }
3498    }
3499
3500    impl<'de> serde::de::Deserialize<'de> for ModelVersion {
3501        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3502        where
3503            D: serde::Deserializer<'de>,
3504        {
3505            deserializer.deserialize_any(wkt::internal::EnumVisitor::<ModelVersion>::new(
3506                ".google.cloud.language.v2.ModerateTextRequest.ModelVersion",
3507            ))
3508        }
3509    }
3510}
3511
3512/// The document moderation response message.
3513#[derive(Clone, Debug, Default, PartialEq)]
3514#[non_exhaustive]
3515pub struct ModerateTextResponse {
3516    /// Harmful and sensitive categories representing the input document.
3517    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
3518
3519    /// The language of the text, which will be the same as the language specified
3520    /// in the request or, if not specified, the automatically-detected language.
3521    /// See [Document.language][] field for more details.
3522    pub language_code: std::string::String,
3523
3524    /// Whether the language is officially supported. The API may still return a
3525    /// response when the language is not supported, but it is on a best effort
3526    /// basis.
3527    pub language_supported: bool,
3528
3529    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3530}
3531
3532impl ModerateTextResponse {
3533    pub fn new() -> Self {
3534        std::default::Default::default()
3535    }
3536
3537    /// Sets the value of [moderation_categories][crate::model::ModerateTextResponse::moderation_categories].
3538    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
3539    where
3540        T: std::iter::IntoIterator<Item = V>,
3541        V: std::convert::Into<crate::model::ClassificationCategory>,
3542    {
3543        use std::iter::Iterator;
3544        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
3545        self
3546    }
3547
3548    /// Sets the value of [language_code][crate::model::ModerateTextResponse::language_code].
3549    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
3550        self.language_code = v.into();
3551        self
3552    }
3553
3554    /// Sets the value of [language_supported][crate::model::ModerateTextResponse::language_supported].
3555    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3556        self.language_supported = v.into();
3557        self
3558    }
3559}
3560
3561impl wkt::message::Message for ModerateTextResponse {
3562    fn typename() -> &'static str {
3563        "type.googleapis.com/google.cloud.language.v2.ModerateTextResponse"
3564    }
3565}
3566
3567#[doc(hidden)]
3568impl<'de> serde::de::Deserialize<'de> for ModerateTextResponse {
3569    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3570    where
3571        D: serde::Deserializer<'de>,
3572    {
3573        #[allow(non_camel_case_types)]
3574        #[doc(hidden)]
3575        #[derive(PartialEq, Eq, Hash)]
3576        enum __FieldTag {
3577            __moderation_categories,
3578            __language_code,
3579            __language_supported,
3580            Unknown(std::string::String),
3581        }
3582        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3583            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3584            where
3585                D: serde::Deserializer<'de>,
3586            {
3587                struct Visitor;
3588                impl<'de> serde::de::Visitor<'de> for Visitor {
3589                    type Value = __FieldTag;
3590                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3591                        formatter.write_str("a field name for ModerateTextResponse")
3592                    }
3593                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3594                    where
3595                        E: serde::de::Error,
3596                    {
3597                        use std::result::Result::Ok;
3598                        use std::string::ToString;
3599                        match value {
3600                            "moderationCategories" => Ok(__FieldTag::__moderation_categories),
3601                            "moderation_categories" => Ok(__FieldTag::__moderation_categories),
3602                            "languageCode" => Ok(__FieldTag::__language_code),
3603                            "language_code" => Ok(__FieldTag::__language_code),
3604                            "languageSupported" => Ok(__FieldTag::__language_supported),
3605                            "language_supported" => Ok(__FieldTag::__language_supported),
3606                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3607                        }
3608                    }
3609                }
3610                deserializer.deserialize_identifier(Visitor)
3611            }
3612        }
3613        struct Visitor;
3614        impl<'de> serde::de::Visitor<'de> for Visitor {
3615            type Value = ModerateTextResponse;
3616            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3617                formatter.write_str("struct ModerateTextResponse")
3618            }
3619            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3620            where
3621                A: serde::de::MapAccess<'de>,
3622            {
3623                #[allow(unused_imports)]
3624                use serde::de::Error;
3625                use std::option::Option::Some;
3626                let mut fields = std::collections::HashSet::new();
3627                let mut result = Self::Value::new();
3628                while let Some(tag) = map.next_key::<__FieldTag>()? {
3629                    #[allow(clippy::match_single_binding)]
3630                    match tag {
3631                        __FieldTag::__moderation_categories => {
3632                            if !fields.insert(__FieldTag::__moderation_categories) {
3633                                return std::result::Result::Err(A::Error::duplicate_field(
3634                                    "multiple values for moderation_categories",
3635                                ));
3636                            }
3637                            result.moderation_categories = map
3638                                .next_value::<std::option::Option<
3639                                    std::vec::Vec<crate::model::ClassificationCategory>,
3640                                >>()?
3641                                .unwrap_or_default();
3642                        }
3643                        __FieldTag::__language_code => {
3644                            if !fields.insert(__FieldTag::__language_code) {
3645                                return std::result::Result::Err(A::Error::duplicate_field(
3646                                    "multiple values for language_code",
3647                                ));
3648                            }
3649                            result.language_code = map
3650                                .next_value::<std::option::Option<std::string::String>>()?
3651                                .unwrap_or_default();
3652                        }
3653                        __FieldTag::__language_supported => {
3654                            if !fields.insert(__FieldTag::__language_supported) {
3655                                return std::result::Result::Err(A::Error::duplicate_field(
3656                                    "multiple values for language_supported",
3657                                ));
3658                            }
3659                            result.language_supported = map
3660                                .next_value::<std::option::Option<bool>>()?
3661                                .unwrap_or_default();
3662                        }
3663                        __FieldTag::Unknown(key) => {
3664                            let value = map.next_value::<serde_json::Value>()?;
3665                            result._unknown_fields.insert(key, value);
3666                        }
3667                    }
3668                }
3669                std::result::Result::Ok(result)
3670            }
3671        }
3672        deserializer.deserialize_any(Visitor)
3673    }
3674}
3675
3676#[doc(hidden)]
3677impl serde::ser::Serialize for ModerateTextResponse {
3678    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3679    where
3680        S: serde::ser::Serializer,
3681    {
3682        use serde::ser::SerializeMap;
3683        #[allow(unused_imports)]
3684        use std::option::Option::Some;
3685        let mut state = serializer.serialize_map(std::option::Option::None)?;
3686        if !self.moderation_categories.is_empty() {
3687            state.serialize_entry("moderationCategories", &self.moderation_categories)?;
3688        }
3689        if !self.language_code.is_empty() {
3690            state.serialize_entry("languageCode", &self.language_code)?;
3691        }
3692        if !wkt::internal::is_default(&self.language_supported) {
3693            state.serialize_entry("languageSupported", &self.language_supported)?;
3694        }
3695        if !self._unknown_fields.is_empty() {
3696            for (key, value) in self._unknown_fields.iter() {
3697                state.serialize_entry(key, &value)?;
3698            }
3699        }
3700        state.end()
3701    }
3702}
3703
3704/// The request message for the text annotation API, which can perform multiple
3705/// analysis types in one call.
3706#[derive(Clone, Debug, Default, PartialEq)]
3707#[non_exhaustive]
3708pub struct AnnotateTextRequest {
3709    /// Required. Input document.
3710    pub document: std::option::Option<crate::model::Document>,
3711
3712    /// Required. The enabled features.
3713    pub features: std::option::Option<crate::model::annotate_text_request::Features>,
3714
3715    /// The encoding type used by the API to calculate offsets.
3716    pub encoding_type: crate::model::EncodingType,
3717
3718    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3719}
3720
3721impl AnnotateTextRequest {
3722    pub fn new() -> Self {
3723        std::default::Default::default()
3724    }
3725
3726    /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
3727    pub fn set_document<T>(mut self, v: T) -> Self
3728    where
3729        T: std::convert::Into<crate::model::Document>,
3730    {
3731        self.document = std::option::Option::Some(v.into());
3732        self
3733    }
3734
3735    /// Sets or clears the value of [document][crate::model::AnnotateTextRequest::document].
3736    pub fn set_or_clear_document<T>(mut self, v: std::option::Option<T>) -> Self
3737    where
3738        T: std::convert::Into<crate::model::Document>,
3739    {
3740        self.document = v.map(|x| x.into());
3741        self
3742    }
3743
3744    /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
3745    pub fn set_features<T>(mut self, v: T) -> Self
3746    where
3747        T: std::convert::Into<crate::model::annotate_text_request::Features>,
3748    {
3749        self.features = std::option::Option::Some(v.into());
3750        self
3751    }
3752
3753    /// Sets or clears the value of [features][crate::model::AnnotateTextRequest::features].
3754    pub fn set_or_clear_features<T>(mut self, v: std::option::Option<T>) -> Self
3755    where
3756        T: std::convert::Into<crate::model::annotate_text_request::Features>,
3757    {
3758        self.features = v.map(|x| x.into());
3759        self
3760    }
3761
3762    /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
3763    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
3764        mut self,
3765        v: T,
3766    ) -> Self {
3767        self.encoding_type = v.into();
3768        self
3769    }
3770}
3771
3772impl wkt::message::Message for AnnotateTextRequest {
3773    fn typename() -> &'static str {
3774        "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest"
3775    }
3776}
3777
3778#[doc(hidden)]
3779impl<'de> serde::de::Deserialize<'de> for AnnotateTextRequest {
3780    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3781    where
3782        D: serde::Deserializer<'de>,
3783    {
3784        #[allow(non_camel_case_types)]
3785        #[doc(hidden)]
3786        #[derive(PartialEq, Eq, Hash)]
3787        enum __FieldTag {
3788            __document,
3789            __features,
3790            __encoding_type,
3791            Unknown(std::string::String),
3792        }
3793        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3794            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3795            where
3796                D: serde::Deserializer<'de>,
3797            {
3798                struct Visitor;
3799                impl<'de> serde::de::Visitor<'de> for Visitor {
3800                    type Value = __FieldTag;
3801                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3802                        formatter.write_str("a field name for AnnotateTextRequest")
3803                    }
3804                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
3805                    where
3806                        E: serde::de::Error,
3807                    {
3808                        use std::result::Result::Ok;
3809                        use std::string::ToString;
3810                        match value {
3811                            "document" => Ok(__FieldTag::__document),
3812                            "features" => Ok(__FieldTag::__features),
3813                            "encodingType" => Ok(__FieldTag::__encoding_type),
3814                            "encoding_type" => Ok(__FieldTag::__encoding_type),
3815                            _ => Ok(__FieldTag::Unknown(value.to_string())),
3816                        }
3817                    }
3818                }
3819                deserializer.deserialize_identifier(Visitor)
3820            }
3821        }
3822        struct Visitor;
3823        impl<'de> serde::de::Visitor<'de> for Visitor {
3824            type Value = AnnotateTextRequest;
3825            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
3826                formatter.write_str("struct AnnotateTextRequest")
3827            }
3828            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
3829            where
3830                A: serde::de::MapAccess<'de>,
3831            {
3832                #[allow(unused_imports)]
3833                use serde::de::Error;
3834                use std::option::Option::Some;
3835                let mut fields = std::collections::HashSet::new();
3836                let mut result = Self::Value::new();
3837                while let Some(tag) = map.next_key::<__FieldTag>()? {
3838                    #[allow(clippy::match_single_binding)]
3839                    match tag {
3840                        __FieldTag::__document => {
3841                            if !fields.insert(__FieldTag::__document) {
3842                                return std::result::Result::Err(A::Error::duplicate_field(
3843                                    "multiple values for document",
3844                                ));
3845                            }
3846                            result.document =
3847                                map.next_value::<std::option::Option<crate::model::Document>>()?;
3848                        }
3849                        __FieldTag::__features => {
3850                            if !fields.insert(__FieldTag::__features) {
3851                                return std::result::Result::Err(A::Error::duplicate_field(
3852                                    "multiple values for features",
3853                                ));
3854                            }
3855                            result.features = map.next_value::<std::option::Option<
3856                                crate::model::annotate_text_request::Features,
3857                            >>()?;
3858                        }
3859                        __FieldTag::__encoding_type => {
3860                            if !fields.insert(__FieldTag::__encoding_type) {
3861                                return std::result::Result::Err(A::Error::duplicate_field(
3862                                    "multiple values for encoding_type",
3863                                ));
3864                            }
3865                            result.encoding_type = map
3866                                .next_value::<std::option::Option<crate::model::EncodingType>>()?
3867                                .unwrap_or_default();
3868                        }
3869                        __FieldTag::Unknown(key) => {
3870                            let value = map.next_value::<serde_json::Value>()?;
3871                            result._unknown_fields.insert(key, value);
3872                        }
3873                    }
3874                }
3875                std::result::Result::Ok(result)
3876            }
3877        }
3878        deserializer.deserialize_any(Visitor)
3879    }
3880}
3881
3882#[doc(hidden)]
3883impl serde::ser::Serialize for AnnotateTextRequest {
3884    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
3885    where
3886        S: serde::ser::Serializer,
3887    {
3888        use serde::ser::SerializeMap;
3889        #[allow(unused_imports)]
3890        use std::option::Option::Some;
3891        let mut state = serializer.serialize_map(std::option::Option::None)?;
3892        if self.document.is_some() {
3893            state.serialize_entry("document", &self.document)?;
3894        }
3895        if self.features.is_some() {
3896            state.serialize_entry("features", &self.features)?;
3897        }
3898        if !wkt::internal::is_default(&self.encoding_type) {
3899            state.serialize_entry("encodingType", &self.encoding_type)?;
3900        }
3901        if !self._unknown_fields.is_empty() {
3902            for (key, value) in self._unknown_fields.iter() {
3903                state.serialize_entry(key, &value)?;
3904            }
3905        }
3906        state.end()
3907    }
3908}
3909
3910/// Defines additional types related to [AnnotateTextRequest].
3911pub mod annotate_text_request {
3912    #[allow(unused_imports)]
3913    use super::*;
3914
3915    /// All available features.
3916    /// Setting each one to true will enable that specific analysis for the input.
3917    #[derive(Clone, Debug, Default, PartialEq)]
3918    #[non_exhaustive]
3919    pub struct Features {
3920        /// Optional. Extract entities.
3921        pub extract_entities: bool,
3922
3923        /// Optional. Extract document-level sentiment.
3924        pub extract_document_sentiment: bool,
3925
3926        /// Optional. Classify the full document into categories.
3927        pub classify_text: bool,
3928
3929        /// Optional. Moderate the document for harmful and sensitive categories.
3930        pub moderate_text: bool,
3931
3932        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
3933    }
3934
3935    impl Features {
3936        pub fn new() -> Self {
3937            std::default::Default::default()
3938        }
3939
3940        /// Sets the value of [extract_entities][crate::model::annotate_text_request::Features::extract_entities].
3941        pub fn set_extract_entities<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3942            self.extract_entities = v.into();
3943            self
3944        }
3945
3946        /// Sets the value of [extract_document_sentiment][crate::model::annotate_text_request::Features::extract_document_sentiment].
3947        pub fn set_extract_document_sentiment<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3948            self.extract_document_sentiment = v.into();
3949            self
3950        }
3951
3952        /// Sets the value of [classify_text][crate::model::annotate_text_request::Features::classify_text].
3953        pub fn set_classify_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3954            self.classify_text = v.into();
3955            self
3956        }
3957
3958        /// Sets the value of [moderate_text][crate::model::annotate_text_request::Features::moderate_text].
3959        pub fn set_moderate_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
3960            self.moderate_text = v.into();
3961            self
3962        }
3963    }
3964
3965    impl wkt::message::Message for Features {
3966        fn typename() -> &'static str {
3967            "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest.Features"
3968        }
3969    }
3970
3971    #[doc(hidden)]
3972    impl<'de> serde::de::Deserialize<'de> for Features {
3973        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3974        where
3975            D: serde::Deserializer<'de>,
3976        {
3977            #[allow(non_camel_case_types)]
3978            #[doc(hidden)]
3979            #[derive(PartialEq, Eq, Hash)]
3980            enum __FieldTag {
3981                __extract_entities,
3982                __extract_document_sentiment,
3983                __classify_text,
3984                __moderate_text,
3985                Unknown(std::string::String),
3986            }
3987            impl<'de> serde::de::Deserialize<'de> for __FieldTag {
3988                fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
3989                where
3990                    D: serde::Deserializer<'de>,
3991                {
3992                    struct Visitor;
3993                    impl<'de> serde::de::Visitor<'de> for Visitor {
3994                        type Value = __FieldTag;
3995                        fn expecting(
3996                            &self,
3997                            formatter: &mut std::fmt::Formatter,
3998                        ) -> std::fmt::Result {
3999                            formatter.write_str("a field name for Features")
4000                        }
4001                        fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
4002                        where
4003                            E: serde::de::Error,
4004                        {
4005                            use std::result::Result::Ok;
4006                            use std::string::ToString;
4007                            match value {
4008                                "extractEntities" => Ok(__FieldTag::__extract_entities),
4009                                "extract_entities" => Ok(__FieldTag::__extract_entities),
4010                                "extractDocumentSentiment" => {
4011                                    Ok(__FieldTag::__extract_document_sentiment)
4012                                }
4013                                "extract_document_sentiment" => {
4014                                    Ok(__FieldTag::__extract_document_sentiment)
4015                                }
4016                                "classifyText" => Ok(__FieldTag::__classify_text),
4017                                "classify_text" => Ok(__FieldTag::__classify_text),
4018                                "moderateText" => Ok(__FieldTag::__moderate_text),
4019                                "moderate_text" => Ok(__FieldTag::__moderate_text),
4020                                _ => Ok(__FieldTag::Unknown(value.to_string())),
4021                            }
4022                        }
4023                    }
4024                    deserializer.deserialize_identifier(Visitor)
4025                }
4026            }
4027            struct Visitor;
4028            impl<'de> serde::de::Visitor<'de> for Visitor {
4029                type Value = Features;
4030                fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4031                    formatter.write_str("struct Features")
4032                }
4033                fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
4034                where
4035                    A: serde::de::MapAccess<'de>,
4036                {
4037                    #[allow(unused_imports)]
4038                    use serde::de::Error;
4039                    use std::option::Option::Some;
4040                    let mut fields = std::collections::HashSet::new();
4041                    let mut result = Self::Value::new();
4042                    while let Some(tag) = map.next_key::<__FieldTag>()? {
4043                        #[allow(clippy::match_single_binding)]
4044                        match tag {
4045                            __FieldTag::__extract_entities => {
4046                                if !fields.insert(__FieldTag::__extract_entities) {
4047                                    return std::result::Result::Err(A::Error::duplicate_field(
4048                                        "multiple values for extract_entities",
4049                                    ));
4050                                }
4051                                result.extract_entities = map
4052                                    .next_value::<std::option::Option<bool>>()?
4053                                    .unwrap_or_default();
4054                            }
4055                            __FieldTag::__extract_document_sentiment => {
4056                                if !fields.insert(__FieldTag::__extract_document_sentiment) {
4057                                    return std::result::Result::Err(A::Error::duplicate_field(
4058                                        "multiple values for extract_document_sentiment",
4059                                    ));
4060                                }
4061                                result.extract_document_sentiment = map
4062                                    .next_value::<std::option::Option<bool>>()?
4063                                    .unwrap_or_default();
4064                            }
4065                            __FieldTag::__classify_text => {
4066                                if !fields.insert(__FieldTag::__classify_text) {
4067                                    return std::result::Result::Err(A::Error::duplicate_field(
4068                                        "multiple values for classify_text",
4069                                    ));
4070                                }
4071                                result.classify_text = map
4072                                    .next_value::<std::option::Option<bool>>()?
4073                                    .unwrap_or_default();
4074                            }
4075                            __FieldTag::__moderate_text => {
4076                                if !fields.insert(__FieldTag::__moderate_text) {
4077                                    return std::result::Result::Err(A::Error::duplicate_field(
4078                                        "multiple values for moderate_text",
4079                                    ));
4080                                }
4081                                result.moderate_text = map
4082                                    .next_value::<std::option::Option<bool>>()?
4083                                    .unwrap_or_default();
4084                            }
4085                            __FieldTag::Unknown(key) => {
4086                                let value = map.next_value::<serde_json::Value>()?;
4087                                result._unknown_fields.insert(key, value);
4088                            }
4089                        }
4090                    }
4091                    std::result::Result::Ok(result)
4092                }
4093            }
4094            deserializer.deserialize_any(Visitor)
4095        }
4096    }
4097
4098    #[doc(hidden)]
4099    impl serde::ser::Serialize for Features {
4100        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4101        where
4102            S: serde::ser::Serializer,
4103        {
4104            use serde::ser::SerializeMap;
4105            #[allow(unused_imports)]
4106            use std::option::Option::Some;
4107            let mut state = serializer.serialize_map(std::option::Option::None)?;
4108            if !wkt::internal::is_default(&self.extract_entities) {
4109                state.serialize_entry("extractEntities", &self.extract_entities)?;
4110            }
4111            if !wkt::internal::is_default(&self.extract_document_sentiment) {
4112                state.serialize_entry(
4113                    "extractDocumentSentiment",
4114                    &self.extract_document_sentiment,
4115                )?;
4116            }
4117            if !wkt::internal::is_default(&self.classify_text) {
4118                state.serialize_entry("classifyText", &self.classify_text)?;
4119            }
4120            if !wkt::internal::is_default(&self.moderate_text) {
4121                state.serialize_entry("moderateText", &self.moderate_text)?;
4122            }
4123            if !self._unknown_fields.is_empty() {
4124                for (key, value) in self._unknown_fields.iter() {
4125                    state.serialize_entry(key, &value)?;
4126                }
4127            }
4128            state.end()
4129        }
4130    }
4131}
4132
4133/// The text annotations response message.
4134#[derive(Clone, Debug, Default, PartialEq)]
4135#[non_exhaustive]
4136pub struct AnnotateTextResponse {
4137    /// Sentences in the input document. Populated if the user enables
4138    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
4139    ///
4140    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
4141    pub sentences: std::vec::Vec<crate::model::Sentence>,
4142
4143    /// Entities, along with their semantic information, in the input document.
4144    /// Populated if the user enables
4145    /// [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]
4146    /// or
4147    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].
4148    ///
4149    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]: crate::model::annotate_text_request::Features::extract_entities
4150    pub entities: std::vec::Vec<crate::model::Entity>,
4151
4152    /// The overall sentiment for the document. Populated if the user enables
4153    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
4154    ///
4155    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
4156    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
4157
4158    /// The language of the text, which will be the same as the language specified
4159    /// in the request or, if not specified, the automatically-detected language.
4160    /// See [Document.language][] field for more details.
4161    pub language_code: std::string::String,
4162
4163    /// Categories identified in the input document.
4164    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
4165
4166    /// Harmful and sensitive categories identified in the input document.
4167    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
4168
4169    /// Whether the language is officially supported by all requested features.
4170    /// The API may still return a response when the language is not supported, but
4171    /// it is on a best effort basis.
4172    pub language_supported: bool,
4173
4174    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
4175}
4176
4177impl AnnotateTextResponse {
4178    pub fn new() -> Self {
4179        std::default::Default::default()
4180    }
4181
4182    /// Sets the value of [sentences][crate::model::AnnotateTextResponse::sentences].
4183    pub fn set_sentences<T, V>(mut self, v: T) -> Self
4184    where
4185        T: std::iter::IntoIterator<Item = V>,
4186        V: std::convert::Into<crate::model::Sentence>,
4187    {
4188        use std::iter::Iterator;
4189        self.sentences = v.into_iter().map(|i| i.into()).collect();
4190        self
4191    }
4192
4193    /// Sets the value of [entities][crate::model::AnnotateTextResponse::entities].
4194    pub fn set_entities<T, V>(mut self, v: T) -> Self
4195    where
4196        T: std::iter::IntoIterator<Item = V>,
4197        V: std::convert::Into<crate::model::Entity>,
4198    {
4199        use std::iter::Iterator;
4200        self.entities = v.into_iter().map(|i| i.into()).collect();
4201        self
4202    }
4203
4204    /// Sets the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
4205    pub fn set_document_sentiment<T>(mut self, v: T) -> Self
4206    where
4207        T: std::convert::Into<crate::model::Sentiment>,
4208    {
4209        self.document_sentiment = std::option::Option::Some(v.into());
4210        self
4211    }
4212
4213    /// Sets or clears the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
4214    pub fn set_or_clear_document_sentiment<T>(mut self, v: std::option::Option<T>) -> Self
4215    where
4216        T: std::convert::Into<crate::model::Sentiment>,
4217    {
4218        self.document_sentiment = v.map(|x| x.into());
4219        self
4220    }
4221
4222    /// Sets the value of [language_code][crate::model::AnnotateTextResponse::language_code].
4223    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
4224        self.language_code = v.into();
4225        self
4226    }
4227
4228    /// Sets the value of [categories][crate::model::AnnotateTextResponse::categories].
4229    pub fn set_categories<T, V>(mut self, v: T) -> Self
4230    where
4231        T: std::iter::IntoIterator<Item = V>,
4232        V: std::convert::Into<crate::model::ClassificationCategory>,
4233    {
4234        use std::iter::Iterator;
4235        self.categories = v.into_iter().map(|i| i.into()).collect();
4236        self
4237    }
4238
4239    /// Sets the value of [moderation_categories][crate::model::AnnotateTextResponse::moderation_categories].
4240    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
4241    where
4242        T: std::iter::IntoIterator<Item = V>,
4243        V: std::convert::Into<crate::model::ClassificationCategory>,
4244    {
4245        use std::iter::Iterator;
4246        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
4247        self
4248    }
4249
4250    /// Sets the value of [language_supported][crate::model::AnnotateTextResponse::language_supported].
4251    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
4252        self.language_supported = v.into();
4253        self
4254    }
4255}
4256
4257impl wkt::message::Message for AnnotateTextResponse {
4258    fn typename() -> &'static str {
4259        "type.googleapis.com/google.cloud.language.v2.AnnotateTextResponse"
4260    }
4261}
4262
4263#[doc(hidden)]
4264impl<'de> serde::de::Deserialize<'de> for AnnotateTextResponse {
4265    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4266    where
4267        D: serde::Deserializer<'de>,
4268    {
4269        #[allow(non_camel_case_types)]
4270        #[doc(hidden)]
4271        #[derive(PartialEq, Eq, Hash)]
4272        enum __FieldTag {
4273            __sentences,
4274            __entities,
4275            __document_sentiment,
4276            __language_code,
4277            __categories,
4278            __moderation_categories,
4279            __language_supported,
4280            Unknown(std::string::String),
4281        }
4282        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
4283            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4284            where
4285                D: serde::Deserializer<'de>,
4286            {
4287                struct Visitor;
4288                impl<'de> serde::de::Visitor<'de> for Visitor {
4289                    type Value = __FieldTag;
4290                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4291                        formatter.write_str("a field name for AnnotateTextResponse")
4292                    }
4293                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
4294                    where
4295                        E: serde::de::Error,
4296                    {
4297                        use std::result::Result::Ok;
4298                        use std::string::ToString;
4299                        match value {
4300                            "sentences" => Ok(__FieldTag::__sentences),
4301                            "entities" => Ok(__FieldTag::__entities),
4302                            "documentSentiment" => Ok(__FieldTag::__document_sentiment),
4303                            "document_sentiment" => Ok(__FieldTag::__document_sentiment),
4304                            "languageCode" => Ok(__FieldTag::__language_code),
4305                            "language_code" => Ok(__FieldTag::__language_code),
4306                            "categories" => Ok(__FieldTag::__categories),
4307                            "moderationCategories" => Ok(__FieldTag::__moderation_categories),
4308                            "moderation_categories" => Ok(__FieldTag::__moderation_categories),
4309                            "languageSupported" => Ok(__FieldTag::__language_supported),
4310                            "language_supported" => Ok(__FieldTag::__language_supported),
4311                            _ => Ok(__FieldTag::Unknown(value.to_string())),
4312                        }
4313                    }
4314                }
4315                deserializer.deserialize_identifier(Visitor)
4316            }
4317        }
4318        struct Visitor;
4319        impl<'de> serde::de::Visitor<'de> for Visitor {
4320            type Value = AnnotateTextResponse;
4321            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
4322                formatter.write_str("struct AnnotateTextResponse")
4323            }
4324            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
4325            where
4326                A: serde::de::MapAccess<'de>,
4327            {
4328                #[allow(unused_imports)]
4329                use serde::de::Error;
4330                use std::option::Option::Some;
4331                let mut fields = std::collections::HashSet::new();
4332                let mut result = Self::Value::new();
4333                while let Some(tag) = map.next_key::<__FieldTag>()? {
4334                    #[allow(clippy::match_single_binding)]
4335                    match tag {
4336                        __FieldTag::__sentences => {
4337                            if !fields.insert(__FieldTag::__sentences) {
4338                                return std::result::Result::Err(A::Error::duplicate_field(
4339                                    "multiple values for sentences",
4340                                ));
4341                            }
4342                            result.sentences = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Sentence>>>()?.unwrap_or_default();
4343                        }
4344                        __FieldTag::__entities => {
4345                            if !fields.insert(__FieldTag::__entities) {
4346                                return std::result::Result::Err(A::Error::duplicate_field(
4347                                    "multiple values for entities",
4348                                ));
4349                            }
4350                            result.entities = map.next_value::<std::option::Option<std::vec::Vec<crate::model::Entity>>>()?.unwrap_or_default();
4351                        }
4352                        __FieldTag::__document_sentiment => {
4353                            if !fields.insert(__FieldTag::__document_sentiment) {
4354                                return std::result::Result::Err(A::Error::duplicate_field(
4355                                    "multiple values for document_sentiment",
4356                                ));
4357                            }
4358                            result.document_sentiment =
4359                                map.next_value::<std::option::Option<crate::model::Sentiment>>()?;
4360                        }
4361                        __FieldTag::__language_code => {
4362                            if !fields.insert(__FieldTag::__language_code) {
4363                                return std::result::Result::Err(A::Error::duplicate_field(
4364                                    "multiple values for language_code",
4365                                ));
4366                            }
4367                            result.language_code = map
4368                                .next_value::<std::option::Option<std::string::String>>()?
4369                                .unwrap_or_default();
4370                        }
4371                        __FieldTag::__categories => {
4372                            if !fields.insert(__FieldTag::__categories) {
4373                                return std::result::Result::Err(A::Error::duplicate_field(
4374                                    "multiple values for categories",
4375                                ));
4376                            }
4377                            result.categories = map
4378                                .next_value::<std::option::Option<
4379                                    std::vec::Vec<crate::model::ClassificationCategory>,
4380                                >>()?
4381                                .unwrap_or_default();
4382                        }
4383                        __FieldTag::__moderation_categories => {
4384                            if !fields.insert(__FieldTag::__moderation_categories) {
4385                                return std::result::Result::Err(A::Error::duplicate_field(
4386                                    "multiple values for moderation_categories",
4387                                ));
4388                            }
4389                            result.moderation_categories = map
4390                                .next_value::<std::option::Option<
4391                                    std::vec::Vec<crate::model::ClassificationCategory>,
4392                                >>()?
4393                                .unwrap_or_default();
4394                        }
4395                        __FieldTag::__language_supported => {
4396                            if !fields.insert(__FieldTag::__language_supported) {
4397                                return std::result::Result::Err(A::Error::duplicate_field(
4398                                    "multiple values for language_supported",
4399                                ));
4400                            }
4401                            result.language_supported = map
4402                                .next_value::<std::option::Option<bool>>()?
4403                                .unwrap_or_default();
4404                        }
4405                        __FieldTag::Unknown(key) => {
4406                            let value = map.next_value::<serde_json::Value>()?;
4407                            result._unknown_fields.insert(key, value);
4408                        }
4409                    }
4410                }
4411                std::result::Result::Ok(result)
4412            }
4413        }
4414        deserializer.deserialize_any(Visitor)
4415    }
4416}
4417
4418#[doc(hidden)]
4419impl serde::ser::Serialize for AnnotateTextResponse {
4420    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4421    where
4422        S: serde::ser::Serializer,
4423    {
4424        use serde::ser::SerializeMap;
4425        #[allow(unused_imports)]
4426        use std::option::Option::Some;
4427        let mut state = serializer.serialize_map(std::option::Option::None)?;
4428        if !self.sentences.is_empty() {
4429            state.serialize_entry("sentences", &self.sentences)?;
4430        }
4431        if !self.entities.is_empty() {
4432            state.serialize_entry("entities", &self.entities)?;
4433        }
4434        if self.document_sentiment.is_some() {
4435            state.serialize_entry("documentSentiment", &self.document_sentiment)?;
4436        }
4437        if !self.language_code.is_empty() {
4438            state.serialize_entry("languageCode", &self.language_code)?;
4439        }
4440        if !self.categories.is_empty() {
4441            state.serialize_entry("categories", &self.categories)?;
4442        }
4443        if !self.moderation_categories.is_empty() {
4444            state.serialize_entry("moderationCategories", &self.moderation_categories)?;
4445        }
4446        if !wkt::internal::is_default(&self.language_supported) {
4447            state.serialize_entry("languageSupported", &self.language_supported)?;
4448        }
4449        if !self._unknown_fields.is_empty() {
4450            for (key, value) in self._unknown_fields.iter() {
4451                state.serialize_entry(key, &value)?;
4452            }
4453        }
4454        state.end()
4455    }
4456}
4457
4458/// Represents the text encoding that the caller uses to process the output.
4459/// Providing an `EncodingType` is recommended because the API provides the
4460/// beginning offsets for various outputs, such as tokens and mentions, and
4461/// languages that natively use different text encodings may access offsets
4462/// differently.
4463///
4464/// # Working with unknown values
4465///
4466/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
4467/// additional enum variants at any time. Adding new variants is not considered
4468/// a breaking change. Applications should write their code in anticipation of:
4469///
4470/// - New values appearing in future releases of the client library, **and**
4471/// - New values received dynamically, without application changes.
4472///
4473/// Please consult the [Working with enums] section in the user guide for some
4474/// guidelines.
4475///
4476/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
4477#[derive(Clone, Debug, PartialEq)]
4478#[non_exhaustive]
4479pub enum EncodingType {
4480    /// If `EncodingType` is not specified, encoding-dependent information (such as
4481    /// `begin_offset`) will be set at `-1`.
4482    None,
4483    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4484    /// on the UTF-8 encoding of the input. C++ and Go are examples of languages
4485    /// that use this encoding natively.
4486    Utf8,
4487    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4488    /// on the UTF-16 encoding of the input. Java and JavaScript are examples of
4489    /// languages that use this encoding natively.
4490    Utf16,
4491    /// Encoding-dependent information (such as `begin_offset`) is calculated based
4492    /// on the UTF-32 encoding of the input. Python is an example of a language
4493    /// that uses this encoding natively.
4494    Utf32,
4495    /// If set, the enum was initialized with an unknown value.
4496    ///
4497    /// Applications can examine the value using [EncodingType::value] or
4498    /// [EncodingType::name].
4499    UnknownValue(encoding_type::UnknownValue),
4500}
4501
4502#[doc(hidden)]
4503pub mod encoding_type {
4504    #[allow(unused_imports)]
4505    use super::*;
4506    #[derive(Clone, Debug, PartialEq)]
4507    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
4508}
4509
4510impl EncodingType {
4511    /// Gets the enum value.
4512    ///
4513    /// Returns `None` if the enum contains an unknown value deserialized from
4514    /// the string representation of enums.
4515    pub fn value(&self) -> std::option::Option<i32> {
4516        match self {
4517            Self::None => std::option::Option::Some(0),
4518            Self::Utf8 => std::option::Option::Some(1),
4519            Self::Utf16 => std::option::Option::Some(2),
4520            Self::Utf32 => std::option::Option::Some(3),
4521            Self::UnknownValue(u) => u.0.value(),
4522        }
4523    }
4524
4525    /// Gets the enum value as a string.
4526    ///
4527    /// Returns `None` if the enum contains an unknown value deserialized from
4528    /// the integer representation of enums.
4529    pub fn name(&self) -> std::option::Option<&str> {
4530        match self {
4531            Self::None => std::option::Option::Some("NONE"),
4532            Self::Utf8 => std::option::Option::Some("UTF8"),
4533            Self::Utf16 => std::option::Option::Some("UTF16"),
4534            Self::Utf32 => std::option::Option::Some("UTF32"),
4535            Self::UnknownValue(u) => u.0.name(),
4536        }
4537    }
4538}
4539
4540impl std::default::Default for EncodingType {
4541    fn default() -> Self {
4542        use std::convert::From;
4543        Self::from(0)
4544    }
4545}
4546
4547impl std::fmt::Display for EncodingType {
4548    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
4549        wkt::internal::display_enum(f, self.name(), self.value())
4550    }
4551}
4552
4553impl std::convert::From<i32> for EncodingType {
4554    fn from(value: i32) -> Self {
4555        match value {
4556            0 => Self::None,
4557            1 => Self::Utf8,
4558            2 => Self::Utf16,
4559            3 => Self::Utf32,
4560            _ => Self::UnknownValue(encoding_type::UnknownValue(
4561                wkt::internal::UnknownEnumValue::Integer(value),
4562            )),
4563        }
4564    }
4565}
4566
4567impl std::convert::From<&str> for EncodingType {
4568    fn from(value: &str) -> Self {
4569        use std::string::ToString;
4570        match value {
4571            "NONE" => Self::None,
4572            "UTF8" => Self::Utf8,
4573            "UTF16" => Self::Utf16,
4574            "UTF32" => Self::Utf32,
4575            _ => Self::UnknownValue(encoding_type::UnknownValue(
4576                wkt::internal::UnknownEnumValue::String(value.to_string()),
4577            )),
4578        }
4579    }
4580}
4581
4582impl serde::ser::Serialize for EncodingType {
4583    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
4584    where
4585        S: serde::Serializer,
4586    {
4587        match self {
4588            Self::None => serializer.serialize_i32(0),
4589            Self::Utf8 => serializer.serialize_i32(1),
4590            Self::Utf16 => serializer.serialize_i32(2),
4591            Self::Utf32 => serializer.serialize_i32(3),
4592            Self::UnknownValue(u) => u.0.serialize(serializer),
4593        }
4594    }
4595}
4596
4597impl<'de> serde::de::Deserialize<'de> for EncodingType {
4598    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
4599    where
4600        D: serde::Deserializer<'de>,
4601    {
4602        deserializer.deserialize_any(wkt::internal::EnumVisitor::<EncodingType>::new(
4603            ".google.cloud.language.v2.EncodingType",
4604        ))
4605    }
4606}