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