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#[serde_with::serde_as]
35#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
36#[serde(default, rename_all = "camelCase")]
37#[non_exhaustive]
38pub struct Document {
39    /// Required. If the type is not set or is `TYPE_UNSPECIFIED`,
40    /// returns an `INVALID_ARGUMENT` error.
41    #[serde(rename = "type")]
42    pub r#type: crate::model::document::Type,
43
44    /// Optional. The language of the document (if not specified, the language is
45    /// automatically detected). Both ISO and BCP-47 language codes are
46    /// accepted.\<br\>
47    /// [Language
48    /// Support](https://cloud.google.com/natural-language/docs/languages) lists
49    /// currently supported languages for each API method. If the language (either
50    /// specified by the caller or automatically detected) is not supported by the
51    /// called API method, an `INVALID_ARGUMENT` error is returned.
52    #[serde(skip_serializing_if = "std::string::String::is_empty")]
53    pub language_code: std::string::String,
54
55    /// The source of the document: a string containing the content or a
56    /// Google Cloud Storage URI.
57    #[serde(flatten, skip_serializing_if = "std::option::Option::is_none")]
58    pub source: std::option::Option<crate::model::document::Source>,
59
60    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
61    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
62}
63
64impl Document {
65    pub fn new() -> Self {
66        std::default::Default::default()
67    }
68
69    /// Sets the value of [r#type][crate::model::Document::type].
70    pub fn set_type<T: std::convert::Into<crate::model::document::Type>>(mut self, v: T) -> Self {
71        self.r#type = v.into();
72        self
73    }
74
75    /// Sets the value of [language_code][crate::model::Document::language_code].
76    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
77        self.language_code = v.into();
78        self
79    }
80
81    /// Sets the value of [source][crate::model::Document::source].
82    ///
83    /// Note that all the setters affecting `source` are mutually
84    /// exclusive.
85    pub fn set_source<
86        T: std::convert::Into<std::option::Option<crate::model::document::Source>>,
87    >(
88        mut self,
89        v: T,
90    ) -> Self {
91        self.source = v.into();
92        self
93    }
94
95    /// The value of [source][crate::model::Document::source]
96    /// if it holds a `Content`, `None` if the field is not set or
97    /// holds a different branch.
98    pub fn content(&self) -> std::option::Option<&std::string::String> {
99        #[allow(unreachable_patterns)]
100        self.source.as_ref().and_then(|v| match v {
101            crate::model::document::Source::Content(v) => std::option::Option::Some(v),
102            _ => std::option::Option::None,
103        })
104    }
105
106    /// Sets the value of [source][crate::model::Document::source]
107    /// to hold a `Content`.
108    ///
109    /// Note that all the setters affecting `source` are
110    /// mutually exclusive.
111    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
112        self.source = std::option::Option::Some(crate::model::document::Source::Content(v.into()));
113        self
114    }
115
116    /// The value of [source][crate::model::Document::source]
117    /// if it holds a `GcsContentUri`, `None` if the field is not set or
118    /// holds a different branch.
119    pub fn gcs_content_uri(&self) -> std::option::Option<&std::string::String> {
120        #[allow(unreachable_patterns)]
121        self.source.as_ref().and_then(|v| match v {
122            crate::model::document::Source::GcsContentUri(v) => std::option::Option::Some(v),
123            _ => std::option::Option::None,
124        })
125    }
126
127    /// Sets the value of [source][crate::model::Document::source]
128    /// to hold a `GcsContentUri`.
129    ///
130    /// Note that all the setters affecting `source` are
131    /// mutually exclusive.
132    pub fn set_gcs_content_uri<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
133        self.source =
134            std::option::Option::Some(crate::model::document::Source::GcsContentUri(v.into()));
135        self
136    }
137}
138
139impl wkt::message::Message for Document {
140    fn typename() -> &'static str {
141        "type.googleapis.com/google.cloud.language.v2.Document"
142    }
143}
144
145/// Defines additional types related to [Document].
146pub mod document {
147    #[allow(unused_imports)]
148    use super::*;
149
150    /// The document types enum.
151    ///
152    /// # Working with unknown values
153    ///
154    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
155    /// additional enum variants at any time. Adding new variants is not considered
156    /// a breaking change. Applications should write their code in anticipation of:
157    ///
158    /// - New values appearing in future releases of the client library, **and**
159    /// - New values received dynamically, without application changes.
160    ///
161    /// Please consult the [Working with enums] section in the user guide for some
162    /// guidelines.
163    ///
164    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
165    #[derive(Clone, Debug, PartialEq)]
166    #[non_exhaustive]
167    pub enum Type {
168        /// The content type is not specified.
169        Unspecified,
170        /// Plain text
171        PlainText,
172        /// HTML
173        Html,
174        /// If set, the enum was initialized with an unknown value.
175        ///
176        /// Applications can examine the value using [Type::value] or
177        /// [Type::name].
178        UnknownValue(r#type::UnknownValue),
179    }
180
181    #[doc(hidden)]
182    pub mod r#type {
183        #[allow(unused_imports)]
184        use super::*;
185        #[derive(Clone, Debug, PartialEq)]
186        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
187    }
188
189    impl Type {
190        /// Gets the enum value.
191        ///
192        /// Returns `None` if the enum contains an unknown value deserialized from
193        /// the string representation of enums.
194        pub fn value(&self) -> std::option::Option<i32> {
195            match self {
196                Self::Unspecified => std::option::Option::Some(0),
197                Self::PlainText => std::option::Option::Some(1),
198                Self::Html => std::option::Option::Some(2),
199                Self::UnknownValue(u) => u.0.value(),
200            }
201        }
202
203        /// Gets the enum value as a string.
204        ///
205        /// Returns `None` if the enum contains an unknown value deserialized from
206        /// the integer representation of enums.
207        pub fn name(&self) -> std::option::Option<&str> {
208            match self {
209                Self::Unspecified => std::option::Option::Some("TYPE_UNSPECIFIED"),
210                Self::PlainText => std::option::Option::Some("PLAIN_TEXT"),
211                Self::Html => std::option::Option::Some("HTML"),
212                Self::UnknownValue(u) => u.0.name(),
213            }
214        }
215    }
216
217    impl std::default::Default for Type {
218        fn default() -> Self {
219            use std::convert::From;
220            Self::from(0)
221        }
222    }
223
224    impl std::fmt::Display for Type {
225        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
226            wkt::internal::display_enum(f, self.name(), self.value())
227        }
228    }
229
230    impl std::convert::From<i32> for Type {
231        fn from(value: i32) -> Self {
232            match value {
233                0 => Self::Unspecified,
234                1 => Self::PlainText,
235                2 => Self::Html,
236                _ => Self::UnknownValue(r#type::UnknownValue(
237                    wkt::internal::UnknownEnumValue::Integer(value),
238                )),
239            }
240        }
241    }
242
243    impl std::convert::From<&str> for Type {
244        fn from(value: &str) -> Self {
245            use std::string::ToString;
246            match value {
247                "TYPE_UNSPECIFIED" => Self::Unspecified,
248                "PLAIN_TEXT" => Self::PlainText,
249                "HTML" => Self::Html,
250                _ => Self::UnknownValue(r#type::UnknownValue(
251                    wkt::internal::UnknownEnumValue::String(value.to_string()),
252                )),
253            }
254        }
255    }
256
257    impl serde::ser::Serialize for Type {
258        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
259        where
260            S: serde::Serializer,
261        {
262            match self {
263                Self::Unspecified => serializer.serialize_i32(0),
264                Self::PlainText => serializer.serialize_i32(1),
265                Self::Html => serializer.serialize_i32(2),
266                Self::UnknownValue(u) => u.0.serialize(serializer),
267            }
268        }
269    }
270
271    impl<'de> serde::de::Deserialize<'de> for Type {
272        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
273        where
274            D: serde::Deserializer<'de>,
275        {
276            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
277                ".google.cloud.language.v2.Document.Type",
278            ))
279        }
280    }
281
282    /// The source of the document: a string containing the content or a
283    /// Google Cloud Storage URI.
284    #[serde_with::serde_as]
285    #[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
286    #[serde(rename_all = "camelCase")]
287    #[non_exhaustive]
288    pub enum Source {
289        /// The content of the input in string format.
290        /// Cloud audit logging exempt since it is based on user data.
291        Content(std::string::String),
292        /// The Google Cloud Storage URI where the file content is located.
293        /// This URI must be of the form: gs://bucket_name/object_name. For more
294        /// details, see <https://cloud.google.com/storage/docs/reference-uris>.
295        /// NOTE: Cloud Storage object versioning is not supported.
296        GcsContentUri(std::string::String),
297    }
298}
299
300/// Represents a sentence in the input document.
301#[serde_with::serde_as]
302#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
303#[serde(default, rename_all = "camelCase")]
304#[non_exhaustive]
305pub struct Sentence {
306    /// The sentence text.
307    #[serde(skip_serializing_if = "std::option::Option::is_none")]
308    pub text: std::option::Option<crate::model::TextSpan>,
309
310    /// For calls to [AnalyzeSentiment][] or if
311    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]
312    /// is set to true, this field will contain the sentiment for the sentence.
313    ///
314    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
315    #[serde(skip_serializing_if = "std::option::Option::is_none")]
316    pub sentiment: std::option::Option<crate::model::Sentiment>,
317
318    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
319    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
320}
321
322impl Sentence {
323    pub fn new() -> Self {
324        std::default::Default::default()
325    }
326
327    /// Sets the value of [text][crate::model::Sentence::text].
328    pub fn set_text<T: std::convert::Into<std::option::Option<crate::model::TextSpan>>>(
329        mut self,
330        v: T,
331    ) -> Self {
332        self.text = v.into();
333        self
334    }
335
336    /// Sets the value of [sentiment][crate::model::Sentence::sentiment].
337    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
338        mut self,
339        v: T,
340    ) -> Self {
341        self.sentiment = v.into();
342        self
343    }
344}
345
346impl wkt::message::Message for Sentence {
347    fn typename() -> &'static str {
348        "type.googleapis.com/google.cloud.language.v2.Sentence"
349    }
350}
351
352/// Represents a phrase in the text that is a known entity, such as
353/// a person, an organization, or location. The API associates information, such
354/// as probability and mentions, with entities.
355#[serde_with::serde_as]
356#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
357#[serde(default, rename_all = "camelCase")]
358#[non_exhaustive]
359pub struct Entity {
360    /// The representative name for the entity.
361    #[serde(skip_serializing_if = "std::string::String::is_empty")]
362    pub name: std::string::String,
363
364    /// The entity type.
365    #[serde(rename = "type")]
366    pub r#type: crate::model::entity::Type,
367
368    /// Metadata associated with the entity.
369    ///
370    /// For the metadata
371    /// associated with other entity types, see the Type table below.
372    #[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
373    pub metadata: std::collections::HashMap<std::string::String, std::string::String>,
374
375    /// The mentions of this entity in the input document. The API currently
376    /// supports proper noun mentions.
377    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
378    pub mentions: std::vec::Vec<crate::model::EntityMention>,
379
380    /// For calls to [AnalyzeEntitySentiment][] or if
381    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
382    /// is set to true, this field will contain the aggregate sentiment expressed
383    /// for this entity in the provided document.
384    #[serde(skip_serializing_if = "std::option::Option::is_none")]
385    pub sentiment: std::option::Option<crate::model::Sentiment>,
386
387    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
388    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
389}
390
391impl Entity {
392    pub fn new() -> Self {
393        std::default::Default::default()
394    }
395
396    /// Sets the value of [name][crate::model::Entity::name].
397    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
398        self.name = v.into();
399        self
400    }
401
402    /// Sets the value of [r#type][crate::model::Entity::type].
403    pub fn set_type<T: std::convert::Into<crate::model::entity::Type>>(mut self, v: T) -> Self {
404        self.r#type = v.into();
405        self
406    }
407
408    /// Sets the value of [metadata][crate::model::Entity::metadata].
409    pub fn set_metadata<T, K, V>(mut self, v: T) -> Self
410    where
411        T: std::iter::IntoIterator<Item = (K, V)>,
412        K: std::convert::Into<std::string::String>,
413        V: std::convert::Into<std::string::String>,
414    {
415        use std::iter::Iterator;
416        self.metadata = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
417        self
418    }
419
420    /// Sets the value of [mentions][crate::model::Entity::mentions].
421    pub fn set_mentions<T, V>(mut self, v: T) -> Self
422    where
423        T: std::iter::IntoIterator<Item = V>,
424        V: std::convert::Into<crate::model::EntityMention>,
425    {
426        use std::iter::Iterator;
427        self.mentions = v.into_iter().map(|i| i.into()).collect();
428        self
429    }
430
431    /// Sets the value of [sentiment][crate::model::Entity::sentiment].
432    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
433        mut self,
434        v: T,
435    ) -> Self {
436        self.sentiment = v.into();
437        self
438    }
439}
440
441impl wkt::message::Message for Entity {
442    fn typename() -> &'static str {
443        "type.googleapis.com/google.cloud.language.v2.Entity"
444    }
445}
446
447/// Defines additional types related to [Entity].
448pub mod entity {
449    #[allow(unused_imports)]
450    use super::*;
451
452    /// The type of the entity. The table
453    /// below lists the associated fields for entities that have different
454    /// metadata.
455    ///
456    /// # Working with unknown values
457    ///
458    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
459    /// additional enum variants at any time. Adding new variants is not considered
460    /// a breaking change. Applications should write their code in anticipation of:
461    ///
462    /// - New values appearing in future releases of the client library, **and**
463    /// - New values received dynamically, without application changes.
464    ///
465    /// Please consult the [Working with enums] section in the user guide for some
466    /// guidelines.
467    ///
468    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
469    #[derive(Clone, Debug, PartialEq)]
470    #[non_exhaustive]
471    pub enum Type {
472        /// Unknown
473        Unknown,
474        /// Person
475        Person,
476        /// Location
477        Location,
478        /// Organization
479        Organization,
480        /// Event
481        Event,
482        /// Artwork
483        WorkOfArt,
484        /// Consumer product
485        ConsumerGood,
486        /// Other types of entities
487        Other,
488        /// Phone number
489        ///
490        /// The metadata lists the phone number, formatted according to local
491        /// convention, plus whichever additional elements appear in the text:
492        ///
493        /// * `number` - the actual number, broken down into sections as per local
494        ///   convention
495        /// * `national_prefix` - country code, if detected
496        /// * `area_code` - region or area code, if detected
497        /// * `extension` - phone extension (to be dialed after connection), if
498        ///   detected
499        PhoneNumber,
500        /// Address
501        ///
502        /// The metadata identifies the street number and locality plus whichever
503        /// additional elements appear in the text:
504        ///
505        /// * `street_number` - street number
506        /// * `locality` - city or town
507        /// * `street_name` - street/route name, if detected
508        /// * `postal_code` - postal code, if detected
509        /// * `country` - country, if detected
510        /// * `broad_region` - administrative area, such as the state, if detected
511        /// * `narrow_region` - smaller administrative area, such as county, if
512        ///   detected
513        /// * `sublocality` - used in Asian addresses to demark a district within a
514        ///   city, if detected
515        Address,
516        /// Date
517        ///
518        /// The metadata identifies the components of the date:
519        ///
520        /// * `year` - four digit year, if detected
521        /// * `month` - two digit month number, if detected
522        /// * `day` - two digit day number, if detected
523        Date,
524        /// Number
525        ///
526        /// The metadata is the number itself.
527        Number,
528        /// Price
529        ///
530        /// The metadata identifies the `value` and `currency`.
531        Price,
532        /// If set, the enum was initialized with an unknown value.
533        ///
534        /// Applications can examine the value using [Type::value] or
535        /// [Type::name].
536        UnknownValue(r#type::UnknownValue),
537    }
538
539    #[doc(hidden)]
540    pub mod r#type {
541        #[allow(unused_imports)]
542        use super::*;
543        #[derive(Clone, Debug, PartialEq)]
544        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
545    }
546
547    impl Type {
548        /// Gets the enum value.
549        ///
550        /// Returns `None` if the enum contains an unknown value deserialized from
551        /// the string representation of enums.
552        pub fn value(&self) -> std::option::Option<i32> {
553            match self {
554                Self::Unknown => std::option::Option::Some(0),
555                Self::Person => std::option::Option::Some(1),
556                Self::Location => std::option::Option::Some(2),
557                Self::Organization => std::option::Option::Some(3),
558                Self::Event => std::option::Option::Some(4),
559                Self::WorkOfArt => std::option::Option::Some(5),
560                Self::ConsumerGood => std::option::Option::Some(6),
561                Self::Other => std::option::Option::Some(7),
562                Self::PhoneNumber => std::option::Option::Some(9),
563                Self::Address => std::option::Option::Some(10),
564                Self::Date => std::option::Option::Some(11),
565                Self::Number => std::option::Option::Some(12),
566                Self::Price => std::option::Option::Some(13),
567                Self::UnknownValue(u) => u.0.value(),
568            }
569        }
570
571        /// Gets the enum value as a string.
572        ///
573        /// Returns `None` if the enum contains an unknown value deserialized from
574        /// the integer representation of enums.
575        pub fn name(&self) -> std::option::Option<&str> {
576            match self {
577                Self::Unknown => std::option::Option::Some("UNKNOWN"),
578                Self::Person => std::option::Option::Some("PERSON"),
579                Self::Location => std::option::Option::Some("LOCATION"),
580                Self::Organization => std::option::Option::Some("ORGANIZATION"),
581                Self::Event => std::option::Option::Some("EVENT"),
582                Self::WorkOfArt => std::option::Option::Some("WORK_OF_ART"),
583                Self::ConsumerGood => std::option::Option::Some("CONSUMER_GOOD"),
584                Self::Other => std::option::Option::Some("OTHER"),
585                Self::PhoneNumber => std::option::Option::Some("PHONE_NUMBER"),
586                Self::Address => std::option::Option::Some("ADDRESS"),
587                Self::Date => std::option::Option::Some("DATE"),
588                Self::Number => std::option::Option::Some("NUMBER"),
589                Self::Price => std::option::Option::Some("PRICE"),
590                Self::UnknownValue(u) => u.0.name(),
591            }
592        }
593    }
594
595    impl std::default::Default for Type {
596        fn default() -> Self {
597            use std::convert::From;
598            Self::from(0)
599        }
600    }
601
602    impl std::fmt::Display for Type {
603        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
604            wkt::internal::display_enum(f, self.name(), self.value())
605        }
606    }
607
608    impl std::convert::From<i32> for Type {
609        fn from(value: i32) -> Self {
610            match value {
611                0 => Self::Unknown,
612                1 => Self::Person,
613                2 => Self::Location,
614                3 => Self::Organization,
615                4 => Self::Event,
616                5 => Self::WorkOfArt,
617                6 => Self::ConsumerGood,
618                7 => Self::Other,
619                9 => Self::PhoneNumber,
620                10 => Self::Address,
621                11 => Self::Date,
622                12 => Self::Number,
623                13 => Self::Price,
624                _ => Self::UnknownValue(r#type::UnknownValue(
625                    wkt::internal::UnknownEnumValue::Integer(value),
626                )),
627            }
628        }
629    }
630
631    impl std::convert::From<&str> for Type {
632        fn from(value: &str) -> Self {
633            use std::string::ToString;
634            match value {
635                "UNKNOWN" => Self::Unknown,
636                "PERSON" => Self::Person,
637                "LOCATION" => Self::Location,
638                "ORGANIZATION" => Self::Organization,
639                "EVENT" => Self::Event,
640                "WORK_OF_ART" => Self::WorkOfArt,
641                "CONSUMER_GOOD" => Self::ConsumerGood,
642                "OTHER" => Self::Other,
643                "PHONE_NUMBER" => Self::PhoneNumber,
644                "ADDRESS" => Self::Address,
645                "DATE" => Self::Date,
646                "NUMBER" => Self::Number,
647                "PRICE" => Self::Price,
648                _ => Self::UnknownValue(r#type::UnknownValue(
649                    wkt::internal::UnknownEnumValue::String(value.to_string()),
650                )),
651            }
652        }
653    }
654
655    impl serde::ser::Serialize for Type {
656        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
657        where
658            S: serde::Serializer,
659        {
660            match self {
661                Self::Unknown => serializer.serialize_i32(0),
662                Self::Person => serializer.serialize_i32(1),
663                Self::Location => serializer.serialize_i32(2),
664                Self::Organization => serializer.serialize_i32(3),
665                Self::Event => serializer.serialize_i32(4),
666                Self::WorkOfArt => serializer.serialize_i32(5),
667                Self::ConsumerGood => serializer.serialize_i32(6),
668                Self::Other => serializer.serialize_i32(7),
669                Self::PhoneNumber => serializer.serialize_i32(9),
670                Self::Address => serializer.serialize_i32(10),
671                Self::Date => serializer.serialize_i32(11),
672                Self::Number => serializer.serialize_i32(12),
673                Self::Price => serializer.serialize_i32(13),
674                Self::UnknownValue(u) => u.0.serialize(serializer),
675            }
676        }
677    }
678
679    impl<'de> serde::de::Deserialize<'de> for Type {
680        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
681        where
682            D: serde::Deserializer<'de>,
683        {
684            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
685                ".google.cloud.language.v2.Entity.Type",
686            ))
687        }
688    }
689}
690
691/// Represents the feeling associated with the entire text or entities in
692/// the text.
693#[serde_with::serde_as]
694#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
695#[serde(default, rename_all = "camelCase")]
696#[non_exhaustive]
697pub struct Sentiment {
698    /// A non-negative number in the [0, +inf) range, which represents
699    /// the absolute magnitude of sentiment regardless of score (positive or
700    /// negative).
701    #[serde(skip_serializing_if = "wkt::internal::is_default")]
702    #[serde_as(as = "wkt::internal::F32")]
703    pub magnitude: f32,
704
705    /// Sentiment score between -1.0 (negative sentiment) and 1.0
706    /// (positive sentiment).
707    #[serde(skip_serializing_if = "wkt::internal::is_default")]
708    #[serde_as(as = "wkt::internal::F32")]
709    pub score: f32,
710
711    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
712    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
713}
714
715impl Sentiment {
716    pub fn new() -> Self {
717        std::default::Default::default()
718    }
719
720    /// Sets the value of [magnitude][crate::model::Sentiment::magnitude].
721    pub fn set_magnitude<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
722        self.magnitude = v.into();
723        self
724    }
725
726    /// Sets the value of [score][crate::model::Sentiment::score].
727    pub fn set_score<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
728        self.score = v.into();
729        self
730    }
731}
732
733impl wkt::message::Message for Sentiment {
734    fn typename() -> &'static str {
735        "type.googleapis.com/google.cloud.language.v2.Sentiment"
736    }
737}
738
739/// Represents a mention for an entity in the text. Currently, proper noun
740/// mentions are supported.
741#[serde_with::serde_as]
742#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
743#[serde(default, rename_all = "camelCase")]
744#[non_exhaustive]
745pub struct EntityMention {
746    /// The mention text.
747    #[serde(skip_serializing_if = "std::option::Option::is_none")]
748    pub text: std::option::Option<crate::model::TextSpan>,
749
750    /// The type of the entity mention.
751    #[serde(rename = "type")]
752    pub r#type: crate::model::entity_mention::Type,
753
754    /// For calls to [AnalyzeEntitySentiment][] or if
755    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment]
756    /// is set to true, this field will contain the sentiment expressed for this
757    /// mention of the entity in the provided document.
758    #[serde(skip_serializing_if = "std::option::Option::is_none")]
759    pub sentiment: std::option::Option<crate::model::Sentiment>,
760
761    /// Probability score associated with the entity.
762    ///
763    /// The score shows the probability of the entity mention being the entity
764    /// type. The score is in (0, 1] range.
765    #[serde(skip_serializing_if = "wkt::internal::is_default")]
766    #[serde_as(as = "wkt::internal::F32")]
767    pub probability: f32,
768
769    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
770    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
771}
772
773impl EntityMention {
774    pub fn new() -> Self {
775        std::default::Default::default()
776    }
777
778    /// Sets the value of [text][crate::model::EntityMention::text].
779    pub fn set_text<T: std::convert::Into<std::option::Option<crate::model::TextSpan>>>(
780        mut self,
781        v: T,
782    ) -> Self {
783        self.text = v.into();
784        self
785    }
786
787    /// Sets the value of [r#type][crate::model::EntityMention::type].
788    pub fn set_type<T: std::convert::Into<crate::model::entity_mention::Type>>(
789        mut self,
790        v: T,
791    ) -> Self {
792        self.r#type = v.into();
793        self
794    }
795
796    /// Sets the value of [sentiment][crate::model::EntityMention::sentiment].
797    pub fn set_sentiment<T: std::convert::Into<std::option::Option<crate::model::Sentiment>>>(
798        mut self,
799        v: T,
800    ) -> Self {
801        self.sentiment = v.into();
802        self
803    }
804
805    /// Sets the value of [probability][crate::model::EntityMention::probability].
806    pub fn set_probability<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
807        self.probability = v.into();
808        self
809    }
810}
811
812impl wkt::message::Message for EntityMention {
813    fn typename() -> &'static str {
814        "type.googleapis.com/google.cloud.language.v2.EntityMention"
815    }
816}
817
818/// Defines additional types related to [EntityMention].
819pub mod entity_mention {
820    #[allow(unused_imports)]
821    use super::*;
822
823    /// The supported types of mentions.
824    ///
825    /// # Working with unknown values
826    ///
827    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
828    /// additional enum variants at any time. Adding new variants is not considered
829    /// a breaking change. Applications should write their code in anticipation of:
830    ///
831    /// - New values appearing in future releases of the client library, **and**
832    /// - New values received dynamically, without application changes.
833    ///
834    /// Please consult the [Working with enums] section in the user guide for some
835    /// guidelines.
836    ///
837    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
838    #[derive(Clone, Debug, PartialEq)]
839    #[non_exhaustive]
840    pub enum Type {
841        /// Unknown
842        Unknown,
843        /// Proper name
844        Proper,
845        /// Common noun (or noun compound)
846        Common,
847        /// If set, the enum was initialized with an unknown value.
848        ///
849        /// Applications can examine the value using [Type::value] or
850        /// [Type::name].
851        UnknownValue(r#type::UnknownValue),
852    }
853
854    #[doc(hidden)]
855    pub mod r#type {
856        #[allow(unused_imports)]
857        use super::*;
858        #[derive(Clone, Debug, PartialEq)]
859        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
860    }
861
862    impl Type {
863        /// Gets the enum value.
864        ///
865        /// Returns `None` if the enum contains an unknown value deserialized from
866        /// the string representation of enums.
867        pub fn value(&self) -> std::option::Option<i32> {
868            match self {
869                Self::Unknown => std::option::Option::Some(0),
870                Self::Proper => std::option::Option::Some(1),
871                Self::Common => std::option::Option::Some(2),
872                Self::UnknownValue(u) => u.0.value(),
873            }
874        }
875
876        /// Gets the enum value as a string.
877        ///
878        /// Returns `None` if the enum contains an unknown value deserialized from
879        /// the integer representation of enums.
880        pub fn name(&self) -> std::option::Option<&str> {
881            match self {
882                Self::Unknown => std::option::Option::Some("TYPE_UNKNOWN"),
883                Self::Proper => std::option::Option::Some("PROPER"),
884                Self::Common => std::option::Option::Some("COMMON"),
885                Self::UnknownValue(u) => u.0.name(),
886            }
887        }
888    }
889
890    impl std::default::Default for Type {
891        fn default() -> Self {
892            use std::convert::From;
893            Self::from(0)
894        }
895    }
896
897    impl std::fmt::Display for Type {
898        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
899            wkt::internal::display_enum(f, self.name(), self.value())
900        }
901    }
902
903    impl std::convert::From<i32> for Type {
904        fn from(value: i32) -> Self {
905            match value {
906                0 => Self::Unknown,
907                1 => Self::Proper,
908                2 => Self::Common,
909                _ => Self::UnknownValue(r#type::UnknownValue(
910                    wkt::internal::UnknownEnumValue::Integer(value),
911                )),
912            }
913        }
914    }
915
916    impl std::convert::From<&str> for Type {
917        fn from(value: &str) -> Self {
918            use std::string::ToString;
919            match value {
920                "TYPE_UNKNOWN" => Self::Unknown,
921                "PROPER" => Self::Proper,
922                "COMMON" => Self::Common,
923                _ => Self::UnknownValue(r#type::UnknownValue(
924                    wkt::internal::UnknownEnumValue::String(value.to_string()),
925                )),
926            }
927        }
928    }
929
930    impl serde::ser::Serialize for Type {
931        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
932        where
933            S: serde::Serializer,
934        {
935            match self {
936                Self::Unknown => serializer.serialize_i32(0),
937                Self::Proper => serializer.serialize_i32(1),
938                Self::Common => serializer.serialize_i32(2),
939                Self::UnknownValue(u) => u.0.serialize(serializer),
940            }
941        }
942    }
943
944    impl<'de> serde::de::Deserialize<'de> for Type {
945        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
946        where
947            D: serde::Deserializer<'de>,
948        {
949            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Type>::new(
950                ".google.cloud.language.v2.EntityMention.Type",
951            ))
952        }
953    }
954}
955
956/// Represents a text span in the input document.
957#[serde_with::serde_as]
958#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
959#[serde(default, rename_all = "camelCase")]
960#[non_exhaustive]
961pub struct TextSpan {
962    /// The content of the text span, which is a substring of the document.
963    #[serde(skip_serializing_if = "std::string::String::is_empty")]
964    pub content: std::string::String,
965
966    /// The API calculates the beginning offset of the content in the original
967    /// document according to the
968    /// [EncodingType][google.cloud.language.v2.EncodingType] specified in the API
969    /// request.
970    ///
971    /// [google.cloud.language.v2.EncodingType]: crate::model::EncodingType
972    #[serde(skip_serializing_if = "wkt::internal::is_default")]
973    pub begin_offset: i32,
974
975    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
976    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
977}
978
979impl TextSpan {
980    pub fn new() -> Self {
981        std::default::Default::default()
982    }
983
984    /// Sets the value of [content][crate::model::TextSpan::content].
985    pub fn set_content<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
986        self.content = v.into();
987        self
988    }
989
990    /// Sets the value of [begin_offset][crate::model::TextSpan::begin_offset].
991    pub fn set_begin_offset<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
992        self.begin_offset = v.into();
993        self
994    }
995}
996
997impl wkt::message::Message for TextSpan {
998    fn typename() -> &'static str {
999        "type.googleapis.com/google.cloud.language.v2.TextSpan"
1000    }
1001}
1002
1003/// Represents a category returned from the text classifier.
1004#[serde_with::serde_as]
1005#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1006#[serde(default, rename_all = "camelCase")]
1007#[non_exhaustive]
1008pub struct ClassificationCategory {
1009    /// The name of the category representing the document.
1010    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1011    pub name: std::string::String,
1012
1013    /// The classifier's confidence of the category. Number represents how certain
1014    /// the classifier is that this category represents the given text.
1015    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1016    #[serde_as(as = "wkt::internal::F32")]
1017    pub confidence: f32,
1018
1019    /// Optional. The classifier's severity of the category. This is only present
1020    /// when the ModerateTextRequest.ModelVersion is set to MODEL_VERSION_2, and
1021    /// the corresponding category has a severity score.
1022    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1023    #[serde_as(as = "wkt::internal::F32")]
1024    pub severity: f32,
1025
1026    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1027    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1028}
1029
1030impl ClassificationCategory {
1031    pub fn new() -> Self {
1032        std::default::Default::default()
1033    }
1034
1035    /// Sets the value of [name][crate::model::ClassificationCategory::name].
1036    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1037        self.name = v.into();
1038        self
1039    }
1040
1041    /// Sets the value of [confidence][crate::model::ClassificationCategory::confidence].
1042    pub fn set_confidence<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1043        self.confidence = v.into();
1044        self
1045    }
1046
1047    /// Sets the value of [severity][crate::model::ClassificationCategory::severity].
1048    pub fn set_severity<T: std::convert::Into<f32>>(mut self, v: T) -> Self {
1049        self.severity = v.into();
1050        self
1051    }
1052}
1053
1054impl wkt::message::Message for ClassificationCategory {
1055    fn typename() -> &'static str {
1056        "type.googleapis.com/google.cloud.language.v2.ClassificationCategory"
1057    }
1058}
1059
1060/// The sentiment analysis request message.
1061#[serde_with::serde_as]
1062#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1063#[serde(default, rename_all = "camelCase")]
1064#[non_exhaustive]
1065pub struct AnalyzeSentimentRequest {
1066    /// Required. Input document.
1067    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1068    pub document: std::option::Option<crate::model::Document>,
1069
1070    /// The encoding type used by the API to calculate sentence offsets.
1071    pub encoding_type: crate::model::EncodingType,
1072
1073    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1074    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1075}
1076
1077impl AnalyzeSentimentRequest {
1078    pub fn new() -> Self {
1079        std::default::Default::default()
1080    }
1081
1082    /// Sets the value of [document][crate::model::AnalyzeSentimentRequest::document].
1083    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1084        mut self,
1085        v: T,
1086    ) -> Self {
1087        self.document = v.into();
1088        self
1089    }
1090
1091    /// Sets the value of [encoding_type][crate::model::AnalyzeSentimentRequest::encoding_type].
1092    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
1093        mut self,
1094        v: T,
1095    ) -> Self {
1096        self.encoding_type = v.into();
1097        self
1098    }
1099}
1100
1101impl wkt::message::Message for AnalyzeSentimentRequest {
1102    fn typename() -> &'static str {
1103        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentRequest"
1104    }
1105}
1106
1107/// The sentiment analysis response message.
1108#[serde_with::serde_as]
1109#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1110#[serde(default, rename_all = "camelCase")]
1111#[non_exhaustive]
1112pub struct AnalyzeSentimentResponse {
1113    /// The overall sentiment of the input document.
1114    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1115    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
1116
1117    /// The language of the text, which will be the same as the language specified
1118    /// in the request or, if not specified, the automatically-detected language.
1119    /// See [Document.language][] field for more details.
1120    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1121    pub language_code: std::string::String,
1122
1123    /// The sentiment for all the sentences in the document.
1124    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1125    pub sentences: std::vec::Vec<crate::model::Sentence>,
1126
1127    /// Whether the language is officially supported. The API may still return a
1128    /// response when the language is not supported, but it is on a best effort
1129    /// basis.
1130    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1131    pub language_supported: bool,
1132
1133    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1134    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1135}
1136
1137impl AnalyzeSentimentResponse {
1138    pub fn new() -> Self {
1139        std::default::Default::default()
1140    }
1141
1142    /// Sets the value of [document_sentiment][crate::model::AnalyzeSentimentResponse::document_sentiment].
1143    pub fn set_document_sentiment<
1144        T: std::convert::Into<std::option::Option<crate::model::Sentiment>>,
1145    >(
1146        mut self,
1147        v: T,
1148    ) -> Self {
1149        self.document_sentiment = v.into();
1150        self
1151    }
1152
1153    /// Sets the value of [language_code][crate::model::AnalyzeSentimentResponse::language_code].
1154    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1155        self.language_code = v.into();
1156        self
1157    }
1158
1159    /// Sets the value of [sentences][crate::model::AnalyzeSentimentResponse::sentences].
1160    pub fn set_sentences<T, V>(mut self, v: T) -> Self
1161    where
1162        T: std::iter::IntoIterator<Item = V>,
1163        V: std::convert::Into<crate::model::Sentence>,
1164    {
1165        use std::iter::Iterator;
1166        self.sentences = v.into_iter().map(|i| i.into()).collect();
1167        self
1168    }
1169
1170    /// Sets the value of [language_supported][crate::model::AnalyzeSentimentResponse::language_supported].
1171    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1172        self.language_supported = v.into();
1173        self
1174    }
1175}
1176
1177impl wkt::message::Message for AnalyzeSentimentResponse {
1178    fn typename() -> &'static str {
1179        "type.googleapis.com/google.cloud.language.v2.AnalyzeSentimentResponse"
1180    }
1181}
1182
1183/// The entity analysis request message.
1184#[serde_with::serde_as]
1185#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1186#[serde(default, rename_all = "camelCase")]
1187#[non_exhaustive]
1188pub struct AnalyzeEntitiesRequest {
1189    /// Required. Input document.
1190    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1191    pub document: std::option::Option<crate::model::Document>,
1192
1193    /// The encoding type used by the API to calculate offsets.
1194    pub encoding_type: crate::model::EncodingType,
1195
1196    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1197    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1198}
1199
1200impl AnalyzeEntitiesRequest {
1201    pub fn new() -> Self {
1202        std::default::Default::default()
1203    }
1204
1205    /// Sets the value of [document][crate::model::AnalyzeEntitiesRequest::document].
1206    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1207        mut self,
1208        v: T,
1209    ) -> Self {
1210        self.document = v.into();
1211        self
1212    }
1213
1214    /// Sets the value of [encoding_type][crate::model::AnalyzeEntitiesRequest::encoding_type].
1215    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
1216        mut self,
1217        v: T,
1218    ) -> Self {
1219        self.encoding_type = v.into();
1220        self
1221    }
1222}
1223
1224impl wkt::message::Message for AnalyzeEntitiesRequest {
1225    fn typename() -> &'static str {
1226        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesRequest"
1227    }
1228}
1229
1230/// The entity analysis response message.
1231#[serde_with::serde_as]
1232#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1233#[serde(default, rename_all = "camelCase")]
1234#[non_exhaustive]
1235pub struct AnalyzeEntitiesResponse {
1236    /// The recognized entities in the input document.
1237    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1238    pub entities: std::vec::Vec<crate::model::Entity>,
1239
1240    /// The language of the text, which will be the same as the language specified
1241    /// in the request or, if not specified, the automatically-detected language.
1242    /// See [Document.language][] field for more details.
1243    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1244    pub language_code: std::string::String,
1245
1246    /// Whether the language is officially supported. The API may still return a
1247    /// response when the language is not supported, but it is on a best effort
1248    /// basis.
1249    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1250    pub language_supported: bool,
1251
1252    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1253    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1254}
1255
1256impl AnalyzeEntitiesResponse {
1257    pub fn new() -> Self {
1258        std::default::Default::default()
1259    }
1260
1261    /// Sets the value of [entities][crate::model::AnalyzeEntitiesResponse::entities].
1262    pub fn set_entities<T, V>(mut self, v: T) -> Self
1263    where
1264        T: std::iter::IntoIterator<Item = V>,
1265        V: std::convert::Into<crate::model::Entity>,
1266    {
1267        use std::iter::Iterator;
1268        self.entities = v.into_iter().map(|i| i.into()).collect();
1269        self
1270    }
1271
1272    /// Sets the value of [language_code][crate::model::AnalyzeEntitiesResponse::language_code].
1273    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1274        self.language_code = v.into();
1275        self
1276    }
1277
1278    /// Sets the value of [language_supported][crate::model::AnalyzeEntitiesResponse::language_supported].
1279    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1280        self.language_supported = v.into();
1281        self
1282    }
1283}
1284
1285impl wkt::message::Message for AnalyzeEntitiesResponse {
1286    fn typename() -> &'static str {
1287        "type.googleapis.com/google.cloud.language.v2.AnalyzeEntitiesResponse"
1288    }
1289}
1290
1291/// The document classification request message.
1292#[serde_with::serde_as]
1293#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1294#[serde(default, rename_all = "camelCase")]
1295#[non_exhaustive]
1296pub struct ClassifyTextRequest {
1297    /// Required. Input document.
1298    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1299    pub document: std::option::Option<crate::model::Document>,
1300
1301    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1302    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1303}
1304
1305impl ClassifyTextRequest {
1306    pub fn new() -> Self {
1307        std::default::Default::default()
1308    }
1309
1310    /// Sets the value of [document][crate::model::ClassifyTextRequest::document].
1311    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1312        mut self,
1313        v: T,
1314    ) -> Self {
1315        self.document = v.into();
1316        self
1317    }
1318}
1319
1320impl wkt::message::Message for ClassifyTextRequest {
1321    fn typename() -> &'static str {
1322        "type.googleapis.com/google.cloud.language.v2.ClassifyTextRequest"
1323    }
1324}
1325
1326/// The document classification response message.
1327#[serde_with::serde_as]
1328#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1329#[serde(default, rename_all = "camelCase")]
1330#[non_exhaustive]
1331pub struct ClassifyTextResponse {
1332    /// Categories representing the input document.
1333    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1334    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
1335
1336    /// The language of the text, which will be the same as the language specified
1337    /// in the request or, if not specified, the automatically-detected language.
1338    /// See [Document.language][] field for more details.
1339    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1340    pub language_code: std::string::String,
1341
1342    /// Whether the language is officially supported. The API may still return a
1343    /// response when the language is not supported, but it is on a best effort
1344    /// basis.
1345    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1346    pub language_supported: bool,
1347
1348    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1349    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1350}
1351
1352impl ClassifyTextResponse {
1353    pub fn new() -> Self {
1354        std::default::Default::default()
1355    }
1356
1357    /// Sets the value of [categories][crate::model::ClassifyTextResponse::categories].
1358    pub fn set_categories<T, V>(mut self, v: T) -> Self
1359    where
1360        T: std::iter::IntoIterator<Item = V>,
1361        V: std::convert::Into<crate::model::ClassificationCategory>,
1362    {
1363        use std::iter::Iterator;
1364        self.categories = v.into_iter().map(|i| i.into()).collect();
1365        self
1366    }
1367
1368    /// Sets the value of [language_code][crate::model::ClassifyTextResponse::language_code].
1369    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1370        self.language_code = v.into();
1371        self
1372    }
1373
1374    /// Sets the value of [language_supported][crate::model::ClassifyTextResponse::language_supported].
1375    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1376        self.language_supported = v.into();
1377        self
1378    }
1379}
1380
1381impl wkt::message::Message for ClassifyTextResponse {
1382    fn typename() -> &'static str {
1383        "type.googleapis.com/google.cloud.language.v2.ClassifyTextResponse"
1384    }
1385}
1386
1387/// The document moderation request message.
1388#[serde_with::serde_as]
1389#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1390#[serde(default, rename_all = "camelCase")]
1391#[non_exhaustive]
1392pub struct ModerateTextRequest {
1393    /// Required. Input document.
1394    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1395    pub document: std::option::Option<crate::model::Document>,
1396
1397    /// Optional. The model version to use for ModerateText.
1398    pub model_version: crate::model::moderate_text_request::ModelVersion,
1399
1400    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1401    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1402}
1403
1404impl ModerateTextRequest {
1405    pub fn new() -> Self {
1406        std::default::Default::default()
1407    }
1408
1409    /// Sets the value of [document][crate::model::ModerateTextRequest::document].
1410    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1411        mut self,
1412        v: T,
1413    ) -> Self {
1414        self.document = v.into();
1415        self
1416    }
1417
1418    /// Sets the value of [model_version][crate::model::ModerateTextRequest::model_version].
1419    pub fn set_model_version<
1420        T: std::convert::Into<crate::model::moderate_text_request::ModelVersion>,
1421    >(
1422        mut self,
1423        v: T,
1424    ) -> Self {
1425        self.model_version = v.into();
1426        self
1427    }
1428}
1429
1430impl wkt::message::Message for ModerateTextRequest {
1431    fn typename() -> &'static str {
1432        "type.googleapis.com/google.cloud.language.v2.ModerateTextRequest"
1433    }
1434}
1435
1436/// Defines additional types related to [ModerateTextRequest].
1437pub mod moderate_text_request {
1438    #[allow(unused_imports)]
1439    use super::*;
1440
1441    /// The model version to use for ModerateText.
1442    ///
1443    /// # Working with unknown values
1444    ///
1445    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
1446    /// additional enum variants at any time. Adding new variants is not considered
1447    /// a breaking change. Applications should write their code in anticipation of:
1448    ///
1449    /// - New values appearing in future releases of the client library, **and**
1450    /// - New values received dynamically, without application changes.
1451    ///
1452    /// Please consult the [Working with enums] section in the user guide for some
1453    /// guidelines.
1454    ///
1455    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
1456    #[derive(Clone, Debug, PartialEq)]
1457    #[non_exhaustive]
1458    pub enum ModelVersion {
1459        /// The default model version.
1460        Unspecified,
1461        /// Use the v1 model, this model is used by default when not provided.
1462        /// The v1 model only returns probability (confidence) score for each
1463        /// category.
1464        _1,
1465        /// Use the v2 model.
1466        /// The v2 model only returns probability (confidence) score for each
1467        /// category, and returns severity score for a subset of the categories.
1468        _2,
1469        /// If set, the enum was initialized with an unknown value.
1470        ///
1471        /// Applications can examine the value using [ModelVersion::value] or
1472        /// [ModelVersion::name].
1473        UnknownValue(model_version::UnknownValue),
1474    }
1475
1476    #[doc(hidden)]
1477    pub mod model_version {
1478        #[allow(unused_imports)]
1479        use super::*;
1480        #[derive(Clone, Debug, PartialEq)]
1481        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
1482    }
1483
1484    impl ModelVersion {
1485        /// Gets the enum value.
1486        ///
1487        /// Returns `None` if the enum contains an unknown value deserialized from
1488        /// the string representation of enums.
1489        pub fn value(&self) -> std::option::Option<i32> {
1490            match self {
1491                Self::Unspecified => std::option::Option::Some(0),
1492                Self::_1 => std::option::Option::Some(1),
1493                Self::_2 => std::option::Option::Some(2),
1494                Self::UnknownValue(u) => u.0.value(),
1495            }
1496        }
1497
1498        /// Gets the enum value as a string.
1499        ///
1500        /// Returns `None` if the enum contains an unknown value deserialized from
1501        /// the integer representation of enums.
1502        pub fn name(&self) -> std::option::Option<&str> {
1503            match self {
1504                Self::Unspecified => std::option::Option::Some("MODEL_VERSION_UNSPECIFIED"),
1505                Self::_1 => std::option::Option::Some("MODEL_VERSION_1"),
1506                Self::_2 => std::option::Option::Some("MODEL_VERSION_2"),
1507                Self::UnknownValue(u) => u.0.name(),
1508            }
1509        }
1510    }
1511
1512    impl std::default::Default for ModelVersion {
1513        fn default() -> Self {
1514            use std::convert::From;
1515            Self::from(0)
1516        }
1517    }
1518
1519    impl std::fmt::Display for ModelVersion {
1520        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1521            wkt::internal::display_enum(f, self.name(), self.value())
1522        }
1523    }
1524
1525    impl std::convert::From<i32> for ModelVersion {
1526        fn from(value: i32) -> Self {
1527            match value {
1528                0 => Self::Unspecified,
1529                1 => Self::_1,
1530                2 => Self::_2,
1531                _ => Self::UnknownValue(model_version::UnknownValue(
1532                    wkt::internal::UnknownEnumValue::Integer(value),
1533                )),
1534            }
1535        }
1536    }
1537
1538    impl std::convert::From<&str> for ModelVersion {
1539        fn from(value: &str) -> Self {
1540            use std::string::ToString;
1541            match value {
1542                "MODEL_VERSION_UNSPECIFIED" => Self::Unspecified,
1543                "MODEL_VERSION_1" => Self::_1,
1544                "MODEL_VERSION_2" => Self::_2,
1545                _ => Self::UnknownValue(model_version::UnknownValue(
1546                    wkt::internal::UnknownEnumValue::String(value.to_string()),
1547                )),
1548            }
1549        }
1550    }
1551
1552    impl serde::ser::Serialize for ModelVersion {
1553        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
1554        where
1555            S: serde::Serializer,
1556        {
1557            match self {
1558                Self::Unspecified => serializer.serialize_i32(0),
1559                Self::_1 => serializer.serialize_i32(1),
1560                Self::_2 => serializer.serialize_i32(2),
1561                Self::UnknownValue(u) => u.0.serialize(serializer),
1562            }
1563        }
1564    }
1565
1566    impl<'de> serde::de::Deserialize<'de> for ModelVersion {
1567        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
1568        where
1569            D: serde::Deserializer<'de>,
1570        {
1571            deserializer.deserialize_any(wkt::internal::EnumVisitor::<ModelVersion>::new(
1572                ".google.cloud.language.v2.ModerateTextRequest.ModelVersion",
1573            ))
1574        }
1575    }
1576}
1577
1578/// The document moderation response message.
1579#[serde_with::serde_as]
1580#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1581#[serde(default, rename_all = "camelCase")]
1582#[non_exhaustive]
1583pub struct ModerateTextResponse {
1584    /// Harmful and sensitive categories representing the input document.
1585    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1586    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
1587
1588    /// The language of the text, which will be the same as the language specified
1589    /// in the request or, if not specified, the automatically-detected language.
1590    /// See [Document.language][] field for more details.
1591    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1592    pub language_code: std::string::String,
1593
1594    /// Whether the language is officially supported. The API may still return a
1595    /// response when the language is not supported, but it is on a best effort
1596    /// basis.
1597    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1598    pub language_supported: bool,
1599
1600    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1601    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1602}
1603
1604impl ModerateTextResponse {
1605    pub fn new() -> Self {
1606        std::default::Default::default()
1607    }
1608
1609    /// Sets the value of [moderation_categories][crate::model::ModerateTextResponse::moderation_categories].
1610    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
1611    where
1612        T: std::iter::IntoIterator<Item = V>,
1613        V: std::convert::Into<crate::model::ClassificationCategory>,
1614    {
1615        use std::iter::Iterator;
1616        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
1617        self
1618    }
1619
1620    /// Sets the value of [language_code][crate::model::ModerateTextResponse::language_code].
1621    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1622        self.language_code = v.into();
1623        self
1624    }
1625
1626    /// Sets the value of [language_supported][crate::model::ModerateTextResponse::language_supported].
1627    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1628        self.language_supported = v.into();
1629        self
1630    }
1631}
1632
1633impl wkt::message::Message for ModerateTextResponse {
1634    fn typename() -> &'static str {
1635        "type.googleapis.com/google.cloud.language.v2.ModerateTextResponse"
1636    }
1637}
1638
1639/// The request message for the text annotation API, which can perform multiple
1640/// analysis types in one call.
1641#[serde_with::serde_as]
1642#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1643#[serde(default, rename_all = "camelCase")]
1644#[non_exhaustive]
1645pub struct AnnotateTextRequest {
1646    /// Required. Input document.
1647    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1648    pub document: std::option::Option<crate::model::Document>,
1649
1650    /// Required. The enabled features.
1651    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1652    pub features: std::option::Option<crate::model::annotate_text_request::Features>,
1653
1654    /// The encoding type used by the API to calculate offsets.
1655    pub encoding_type: crate::model::EncodingType,
1656
1657    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1658    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1659}
1660
1661impl AnnotateTextRequest {
1662    pub fn new() -> Self {
1663        std::default::Default::default()
1664    }
1665
1666    /// Sets the value of [document][crate::model::AnnotateTextRequest::document].
1667    pub fn set_document<T: std::convert::Into<std::option::Option<crate::model::Document>>>(
1668        mut self,
1669        v: T,
1670    ) -> Self {
1671        self.document = v.into();
1672        self
1673    }
1674
1675    /// Sets the value of [features][crate::model::AnnotateTextRequest::features].
1676    pub fn set_features<
1677        T: std::convert::Into<std::option::Option<crate::model::annotate_text_request::Features>>,
1678    >(
1679        mut self,
1680        v: T,
1681    ) -> Self {
1682        self.features = v.into();
1683        self
1684    }
1685
1686    /// Sets the value of [encoding_type][crate::model::AnnotateTextRequest::encoding_type].
1687    pub fn set_encoding_type<T: std::convert::Into<crate::model::EncodingType>>(
1688        mut self,
1689        v: T,
1690    ) -> Self {
1691        self.encoding_type = v.into();
1692        self
1693    }
1694}
1695
1696impl wkt::message::Message for AnnotateTextRequest {
1697    fn typename() -> &'static str {
1698        "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest"
1699    }
1700}
1701
1702/// Defines additional types related to [AnnotateTextRequest].
1703pub mod annotate_text_request {
1704    #[allow(unused_imports)]
1705    use super::*;
1706
1707    /// All available features.
1708    /// Setting each one to true will enable that specific analysis for the input.
1709    #[serde_with::serde_as]
1710    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1711    #[serde(default, rename_all = "camelCase")]
1712    #[non_exhaustive]
1713    pub struct Features {
1714        /// Optional. Extract entities.
1715        #[serde(skip_serializing_if = "wkt::internal::is_default")]
1716        pub extract_entities: bool,
1717
1718        /// Optional. Extract document-level sentiment.
1719        #[serde(skip_serializing_if = "wkt::internal::is_default")]
1720        pub extract_document_sentiment: bool,
1721
1722        /// Optional. Classify the full document into categories.
1723        #[serde(skip_serializing_if = "wkt::internal::is_default")]
1724        pub classify_text: bool,
1725
1726        /// Optional. Moderate the document for harmful and sensitive categories.
1727        #[serde(skip_serializing_if = "wkt::internal::is_default")]
1728        pub moderate_text: bool,
1729
1730        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1731        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1732    }
1733
1734    impl Features {
1735        pub fn new() -> Self {
1736            std::default::Default::default()
1737        }
1738
1739        /// Sets the value of [extract_entities][crate::model::annotate_text_request::Features::extract_entities].
1740        pub fn set_extract_entities<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1741            self.extract_entities = v.into();
1742            self
1743        }
1744
1745        /// Sets the value of [extract_document_sentiment][crate::model::annotate_text_request::Features::extract_document_sentiment].
1746        pub fn set_extract_document_sentiment<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1747            self.extract_document_sentiment = v.into();
1748            self
1749        }
1750
1751        /// Sets the value of [classify_text][crate::model::annotate_text_request::Features::classify_text].
1752        pub fn set_classify_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1753            self.classify_text = v.into();
1754            self
1755        }
1756
1757        /// Sets the value of [moderate_text][crate::model::annotate_text_request::Features::moderate_text].
1758        pub fn set_moderate_text<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1759            self.moderate_text = v.into();
1760            self
1761        }
1762    }
1763
1764    impl wkt::message::Message for Features {
1765        fn typename() -> &'static str {
1766            "type.googleapis.com/google.cloud.language.v2.AnnotateTextRequest.Features"
1767        }
1768    }
1769}
1770
1771/// The text annotations response message.
1772#[serde_with::serde_as]
1773#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1774#[serde(default, rename_all = "camelCase")]
1775#[non_exhaustive]
1776pub struct AnnotateTextResponse {
1777    /// Sentences in the input document. Populated if the user enables
1778    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
1779    ///
1780    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
1781    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1782    pub sentences: std::vec::Vec<crate::model::Sentence>,
1783
1784    /// Entities, along with their semantic information, in the input document.
1785    /// Populated if the user enables
1786    /// [AnnotateTextRequest.Features.extract_entities][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]
1787    /// or
1788    /// [AnnotateTextRequest.Features.extract_entity_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_entity_sentiment].
1789    ///
1790    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_entities]: crate::model::annotate_text_request::Features::extract_entities
1791    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1792    pub entities: std::vec::Vec<crate::model::Entity>,
1793
1794    /// The overall sentiment for the document. Populated if the user enables
1795    /// [AnnotateTextRequest.Features.extract_document_sentiment][google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment].
1796    ///
1797    /// [google.cloud.language.v2.AnnotateTextRequest.Features.extract_document_sentiment]: crate::model::annotate_text_request::Features::extract_document_sentiment
1798    #[serde(skip_serializing_if = "std::option::Option::is_none")]
1799    pub document_sentiment: std::option::Option<crate::model::Sentiment>,
1800
1801    /// The language of the text, which will be the same as the language specified
1802    /// in the request or, if not specified, the automatically-detected language.
1803    /// See [Document.language][] field for more details.
1804    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1805    pub language_code: std::string::String,
1806
1807    /// Categories identified in the input document.
1808    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1809    pub categories: std::vec::Vec<crate::model::ClassificationCategory>,
1810
1811    /// Harmful and sensitive categories identified in the input document.
1812    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1813    pub moderation_categories: std::vec::Vec<crate::model::ClassificationCategory>,
1814
1815    /// Whether the language is officially supported by all requested features.
1816    /// The API may still return a response when the language is not supported, but
1817    /// it is on a best effort basis.
1818    #[serde(skip_serializing_if = "wkt::internal::is_default")]
1819    pub language_supported: bool,
1820
1821    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1822    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1823}
1824
1825impl AnnotateTextResponse {
1826    pub fn new() -> Self {
1827        std::default::Default::default()
1828    }
1829
1830    /// Sets the value of [sentences][crate::model::AnnotateTextResponse::sentences].
1831    pub fn set_sentences<T, V>(mut self, v: T) -> Self
1832    where
1833        T: std::iter::IntoIterator<Item = V>,
1834        V: std::convert::Into<crate::model::Sentence>,
1835    {
1836        use std::iter::Iterator;
1837        self.sentences = v.into_iter().map(|i| i.into()).collect();
1838        self
1839    }
1840
1841    /// Sets the value of [entities][crate::model::AnnotateTextResponse::entities].
1842    pub fn set_entities<T, V>(mut self, v: T) -> Self
1843    where
1844        T: std::iter::IntoIterator<Item = V>,
1845        V: std::convert::Into<crate::model::Entity>,
1846    {
1847        use std::iter::Iterator;
1848        self.entities = v.into_iter().map(|i| i.into()).collect();
1849        self
1850    }
1851
1852    /// Sets the value of [document_sentiment][crate::model::AnnotateTextResponse::document_sentiment].
1853    pub fn set_document_sentiment<
1854        T: std::convert::Into<std::option::Option<crate::model::Sentiment>>,
1855    >(
1856        mut self,
1857        v: T,
1858    ) -> Self {
1859        self.document_sentiment = v.into();
1860        self
1861    }
1862
1863    /// Sets the value of [language_code][crate::model::AnnotateTextResponse::language_code].
1864    pub fn set_language_code<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1865        self.language_code = v.into();
1866        self
1867    }
1868
1869    /// Sets the value of [categories][crate::model::AnnotateTextResponse::categories].
1870    pub fn set_categories<T, V>(mut self, v: T) -> Self
1871    where
1872        T: std::iter::IntoIterator<Item = V>,
1873        V: std::convert::Into<crate::model::ClassificationCategory>,
1874    {
1875        use std::iter::Iterator;
1876        self.categories = v.into_iter().map(|i| i.into()).collect();
1877        self
1878    }
1879
1880    /// Sets the value of [moderation_categories][crate::model::AnnotateTextResponse::moderation_categories].
1881    pub fn set_moderation_categories<T, V>(mut self, v: T) -> Self
1882    where
1883        T: std::iter::IntoIterator<Item = V>,
1884        V: std::convert::Into<crate::model::ClassificationCategory>,
1885    {
1886        use std::iter::Iterator;
1887        self.moderation_categories = v.into_iter().map(|i| i.into()).collect();
1888        self
1889    }
1890
1891    /// Sets the value of [language_supported][crate::model::AnnotateTextResponse::language_supported].
1892    pub fn set_language_supported<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
1893        self.language_supported = v.into();
1894        self
1895    }
1896}
1897
1898impl wkt::message::Message for AnnotateTextResponse {
1899    fn typename() -> &'static str {
1900        "type.googleapis.com/google.cloud.language.v2.AnnotateTextResponse"
1901    }
1902}
1903
1904/// Represents the text encoding that the caller uses to process the output.
1905/// Providing an `EncodingType` is recommended because the API provides the
1906/// beginning offsets for various outputs, such as tokens and mentions, and
1907/// languages that natively use different text encodings may access offsets
1908/// differently.
1909///
1910/// # Working with unknown values
1911///
1912/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
1913/// additional enum variants at any time. Adding new variants is not considered
1914/// a breaking change. Applications should write their code in anticipation of:
1915///
1916/// - New values appearing in future releases of the client library, **and**
1917/// - New values received dynamically, without application changes.
1918///
1919/// Please consult the [Working with enums] section in the user guide for some
1920/// guidelines.
1921///
1922/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
1923#[derive(Clone, Debug, PartialEq)]
1924#[non_exhaustive]
1925pub enum EncodingType {
1926    /// If `EncodingType` is not specified, encoding-dependent information (such as
1927    /// `begin_offset`) will be set at `-1`.
1928    None,
1929    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1930    /// on the UTF-8 encoding of the input. C++ and Go are examples of languages
1931    /// that use this encoding natively.
1932    Utf8,
1933    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1934    /// on the UTF-16 encoding of the input. Java and JavaScript are examples of
1935    /// languages that use this encoding natively.
1936    Utf16,
1937    /// Encoding-dependent information (such as `begin_offset`) is calculated based
1938    /// on the UTF-32 encoding of the input. Python is an example of a language
1939    /// that uses this encoding natively.
1940    Utf32,
1941    /// If set, the enum was initialized with an unknown value.
1942    ///
1943    /// Applications can examine the value using [EncodingType::value] or
1944    /// [EncodingType::name].
1945    UnknownValue(encoding_type::UnknownValue),
1946}
1947
1948#[doc(hidden)]
1949pub mod encoding_type {
1950    #[allow(unused_imports)]
1951    use super::*;
1952    #[derive(Clone, Debug, PartialEq)]
1953    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
1954}
1955
1956impl EncodingType {
1957    /// Gets the enum value.
1958    ///
1959    /// Returns `None` if the enum contains an unknown value deserialized from
1960    /// the string representation of enums.
1961    pub fn value(&self) -> std::option::Option<i32> {
1962        match self {
1963            Self::None => std::option::Option::Some(0),
1964            Self::Utf8 => std::option::Option::Some(1),
1965            Self::Utf16 => std::option::Option::Some(2),
1966            Self::Utf32 => std::option::Option::Some(3),
1967            Self::UnknownValue(u) => u.0.value(),
1968        }
1969    }
1970
1971    /// Gets the enum value as a string.
1972    ///
1973    /// Returns `None` if the enum contains an unknown value deserialized from
1974    /// the integer representation of enums.
1975    pub fn name(&self) -> std::option::Option<&str> {
1976        match self {
1977            Self::None => std::option::Option::Some("NONE"),
1978            Self::Utf8 => std::option::Option::Some("UTF8"),
1979            Self::Utf16 => std::option::Option::Some("UTF16"),
1980            Self::Utf32 => std::option::Option::Some("UTF32"),
1981            Self::UnknownValue(u) => u.0.name(),
1982        }
1983    }
1984}
1985
1986impl std::default::Default for EncodingType {
1987    fn default() -> Self {
1988        use std::convert::From;
1989        Self::from(0)
1990    }
1991}
1992
1993impl std::fmt::Display for EncodingType {
1994    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
1995        wkt::internal::display_enum(f, self.name(), self.value())
1996    }
1997}
1998
1999impl std::convert::From<i32> for EncodingType {
2000    fn from(value: i32) -> Self {
2001        match value {
2002            0 => Self::None,
2003            1 => Self::Utf8,
2004            2 => Self::Utf16,
2005            3 => Self::Utf32,
2006            _ => Self::UnknownValue(encoding_type::UnknownValue(
2007                wkt::internal::UnknownEnumValue::Integer(value),
2008            )),
2009        }
2010    }
2011}
2012
2013impl std::convert::From<&str> for EncodingType {
2014    fn from(value: &str) -> Self {
2015        use std::string::ToString;
2016        match value {
2017            "NONE" => Self::None,
2018            "UTF8" => Self::Utf8,
2019            "UTF16" => Self::Utf16,
2020            "UTF32" => Self::Utf32,
2021            _ => Self::UnknownValue(encoding_type::UnknownValue(
2022                wkt::internal::UnknownEnumValue::String(value.to_string()),
2023            )),
2024        }
2025    }
2026}
2027
2028impl serde::ser::Serialize for EncodingType {
2029    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
2030    where
2031        S: serde::Serializer,
2032    {
2033        match self {
2034            Self::None => serializer.serialize_i32(0),
2035            Self::Utf8 => serializer.serialize_i32(1),
2036            Self::Utf16 => serializer.serialize_i32(2),
2037            Self::Utf32 => serializer.serialize_i32(3),
2038            Self::UnknownValue(u) => u.0.serialize(serializer),
2039        }
2040    }
2041}
2042
2043impl<'de> serde::de::Deserialize<'de> for EncodingType {
2044    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
2045    where
2046        D: serde::Deserializer<'de>,
2047    {
2048        deserializer.deserialize_any(wkt::internal::EnumVisitor::<EncodingType>::new(
2049            ".google.cloud.language.v2.EncodingType",
2050        ))
2051    }
2052}