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