google_cloud_rpc/
model.rs

1// Copyright 2024 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 bytes;
21extern crate serde;
22extern crate serde_json;
23extern crate serde_with;
24extern crate std;
25extern crate wkt;
26
27/// Describes the cause of the error with structured details.
28///
29/// Example of an error when contacting the "pubsub.googleapis.com" API when it
30/// is not enabled:
31///
32/// ```norust
33/// { "reason": "API_DISABLED"
34///   "domain": "googleapis.com"
35///   "metadata": {
36///     "resource": "projects/123",
37///     "service": "pubsub.googleapis.com"
38///   }
39/// }
40/// ```
41///
42/// This response indicates that the pubsub.googleapis.com API is not enabled.
43///
44/// Example of an error that is returned when attempting to create a Spanner
45/// instance in a region that is out of stock:
46///
47/// ```norust
48/// { "reason": "STOCKOUT"
49///   "domain": "spanner.googleapis.com",
50///   "metadata": {
51///     "availableRegions": "us-central1,us-east2"
52///   }
53/// }
54/// ```
55#[serde_with::serde_as]
56#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
57#[serde(default, rename_all = "camelCase")]
58#[non_exhaustive]
59pub struct ErrorInfo {
60    /// The reason of the error. This is a constant value that identifies the
61    /// proximate cause of the error. Error reasons are unique within a particular
62    /// domain of errors. This should be at most 63 characters and match a
63    /// regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`, which represents
64    /// UPPER_SNAKE_CASE.
65    #[serde(skip_serializing_if = "std::string::String::is_empty")]
66    pub reason: std::string::String,
67
68    /// The logical grouping to which the "reason" belongs. The error domain
69    /// is typically the registered service name of the tool or product that
70    /// generates the error. Example: "pubsub.googleapis.com". If the error is
71    /// generated by some common infrastructure, the error domain must be a
72    /// globally unique value that identifies the infrastructure. For Google API
73    /// infrastructure, the error domain is "googleapis.com".
74    #[serde(skip_serializing_if = "std::string::String::is_empty")]
75    pub domain: std::string::String,
76
77    /// Additional structured details about this error.
78    ///
79    /// Keys must match a regular expression of `[a-z][a-zA-Z0-9-_]+` but should
80    /// ideally be lowerCamelCase. Also, they must be limited to 64 characters in
81    /// length. When identifying the current value of an exceeded limit, the units
82    /// should be contained in the key, not the value.  For example, rather than
83    /// `{"instanceLimit": "100/request"}`, should be returned as,
84    /// `{"instanceLimitPerRequest": "100"}`, if the client exceeds the number of
85    /// instances that can be created in a single (batch) request.
86    #[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
87    pub metadata: std::collections::HashMap<std::string::String, std::string::String>,
88
89    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
90    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
91}
92
93impl ErrorInfo {
94    pub fn new() -> Self {
95        std::default::Default::default()
96    }
97
98    /// Sets the value of [reason][crate::model::ErrorInfo::reason].
99    pub fn set_reason<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
100        self.reason = v.into();
101        self
102    }
103
104    /// Sets the value of [domain][crate::model::ErrorInfo::domain].
105    pub fn set_domain<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
106        self.domain = v.into();
107        self
108    }
109
110    /// Sets the value of [metadata][crate::model::ErrorInfo::metadata].
111    pub fn set_metadata<T, K, V>(mut self, v: T) -> Self
112    where
113        T: std::iter::IntoIterator<Item = (K, V)>,
114        K: std::convert::Into<std::string::String>,
115        V: std::convert::Into<std::string::String>,
116    {
117        use std::iter::Iterator;
118        self.metadata = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
119        self
120    }
121}
122
123impl wkt::message::Message for ErrorInfo {
124    fn typename() -> &'static str {
125        "type.googleapis.com/google.rpc.ErrorInfo"
126    }
127}
128
129/// Describes when the clients can retry a failed request. Clients could ignore
130/// the recommendation here or retry when this information is missing from error
131/// responses.
132///
133/// It's always recommended that clients should use exponential backoff when
134/// retrying.
135///
136/// Clients should wait until `retry_delay` amount of time has passed since
137/// receiving the error response before retrying.  If retrying requests also
138/// fail, clients should use an exponential backoff scheme to gradually increase
139/// the delay between retries based on `retry_delay`, until either a maximum
140/// number of retries have been reached or a maximum retry delay cap has been
141/// reached.
142#[serde_with::serde_as]
143#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
144#[serde(default, rename_all = "camelCase")]
145#[non_exhaustive]
146pub struct RetryInfo {
147    /// Clients should wait at least this long between retrying the same request.
148    #[serde(skip_serializing_if = "std::option::Option::is_none")]
149    pub retry_delay: std::option::Option<wkt::Duration>,
150
151    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
152    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
153}
154
155impl RetryInfo {
156    pub fn new() -> Self {
157        std::default::Default::default()
158    }
159
160    /// Sets the value of [retry_delay][crate::model::RetryInfo::retry_delay].
161    pub fn set_retry_delay<T: std::convert::Into<std::option::Option<wkt::Duration>>>(
162        mut self,
163        v: T,
164    ) -> Self {
165        self.retry_delay = v.into();
166        self
167    }
168}
169
170impl wkt::message::Message for RetryInfo {
171    fn typename() -> &'static str {
172        "type.googleapis.com/google.rpc.RetryInfo"
173    }
174}
175
176/// Describes additional debugging info.
177#[serde_with::serde_as]
178#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
179#[serde(default, rename_all = "camelCase")]
180#[non_exhaustive]
181pub struct DebugInfo {
182    /// The stack trace entries indicating where the error occurred.
183    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
184    pub stack_entries: std::vec::Vec<std::string::String>,
185
186    /// Additional debugging information provided by the server.
187    #[serde(skip_serializing_if = "std::string::String::is_empty")]
188    pub detail: std::string::String,
189
190    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
191    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
192}
193
194impl DebugInfo {
195    pub fn new() -> Self {
196        std::default::Default::default()
197    }
198
199    /// Sets the value of [detail][crate::model::DebugInfo::detail].
200    pub fn set_detail<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
201        self.detail = v.into();
202        self
203    }
204
205    /// Sets the value of [stack_entries][crate::model::DebugInfo::stack_entries].
206    pub fn set_stack_entries<T, V>(mut self, v: T) -> Self
207    where
208        T: std::iter::IntoIterator<Item = V>,
209        V: std::convert::Into<std::string::String>,
210    {
211        use std::iter::Iterator;
212        self.stack_entries = v.into_iter().map(|i| i.into()).collect();
213        self
214    }
215}
216
217impl wkt::message::Message for DebugInfo {
218    fn typename() -> &'static str {
219        "type.googleapis.com/google.rpc.DebugInfo"
220    }
221}
222
223/// Describes how a quota check failed.
224///
225/// For example if a daily limit was exceeded for the calling project,
226/// a service could respond with a QuotaFailure detail containing the project
227/// id and the description of the quota limit that was exceeded.  If the
228/// calling project hasn't enabled the service in the developer console, then
229/// a service could respond with the project id and set `service_disabled`
230/// to true.
231///
232/// Also see RetryInfo and Help types for other details about handling a
233/// quota failure.
234#[serde_with::serde_as]
235#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
236#[serde(default, rename_all = "camelCase")]
237#[non_exhaustive]
238pub struct QuotaFailure {
239    /// Describes all quota violations.
240    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
241    pub violations: std::vec::Vec<crate::model::quota_failure::Violation>,
242
243    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
244    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
245}
246
247impl QuotaFailure {
248    pub fn new() -> Self {
249        std::default::Default::default()
250    }
251
252    /// Sets the value of [violations][crate::model::QuotaFailure::violations].
253    pub fn set_violations<T, V>(mut self, v: T) -> Self
254    where
255        T: std::iter::IntoIterator<Item = V>,
256        V: std::convert::Into<crate::model::quota_failure::Violation>,
257    {
258        use std::iter::Iterator;
259        self.violations = v.into_iter().map(|i| i.into()).collect();
260        self
261    }
262}
263
264impl wkt::message::Message for QuotaFailure {
265    fn typename() -> &'static str {
266        "type.googleapis.com/google.rpc.QuotaFailure"
267    }
268}
269
270/// Defines additional types related to [QuotaFailure].
271pub mod quota_failure {
272    #[allow(unused_imports)]
273    use super::*;
274
275    /// A message type used to describe a single quota violation.  For example, a
276    /// daily quota or a custom quota that was exceeded.
277    #[serde_with::serde_as]
278    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
279    #[serde(default, rename_all = "camelCase")]
280    #[non_exhaustive]
281    pub struct Violation {
282        /// The subject on which the quota check failed.
283        /// For example, "clientip:\<ip address of client\>" or "project:\<Google
284        /// developer project id\>".
285        #[serde(skip_serializing_if = "std::string::String::is_empty")]
286        pub subject: std::string::String,
287
288        /// A description of how the quota check failed. Clients can use this
289        /// description to find more about the quota configuration in the service's
290        /// public documentation, or find the relevant quota limit to adjust through
291        /// developer console.
292        ///
293        /// For example: "Service disabled" or "Daily Limit for read operations
294        /// exceeded".
295        #[serde(skip_serializing_if = "std::string::String::is_empty")]
296        pub description: std::string::String,
297
298        /// The API Service from which the `QuotaFailure.Violation` orginates. In
299        /// some cases, Quota issues originate from an API Service other than the one
300        /// that was called. In other words, a dependency of the called API Service
301        /// could be the cause of the `QuotaFailure`, and this field would have the
302        /// dependency API service name.
303        ///
304        /// For example, if the called API is Kubernetes Engine API
305        /// (container.googleapis.com), and a quota violation occurs in the
306        /// Kubernetes Engine API itself, this field would be
307        /// "container.googleapis.com". On the other hand, if the quota violation
308        /// occurs when the Kubernetes Engine API creates VMs in the Compute Engine
309        /// API (compute.googleapis.com), this field would be
310        /// "compute.googleapis.com".
311        #[serde(skip_serializing_if = "std::string::String::is_empty")]
312        pub api_service: std::string::String,
313
314        /// The metric of the violated quota. A quota metric is a named counter to
315        /// measure usage, such as API requests or CPUs. When an activity occurs in a
316        /// service, such as Virtual Machine allocation, one or more quota metrics
317        /// may be affected.
318        ///
319        /// For example, "compute.googleapis.com/cpus_per_vm_family",
320        /// "storage.googleapis.com/internet_egress_bandwidth".
321        #[serde(skip_serializing_if = "std::string::String::is_empty")]
322        pub quota_metric: std::string::String,
323
324        /// The id of the violated quota. Also know as "limit name", this is the
325        /// unique identifier of a quota in the context of an API service.
326        ///
327        /// For example, "CPUS-PER-VM-FAMILY-per-project-region".
328        #[serde(skip_serializing_if = "std::string::String::is_empty")]
329        pub quota_id: std::string::String,
330
331        /// The dimensions of the violated quota. Every non-global quota is enforced
332        /// on a set of dimensions. While quota metric defines what to count, the
333        /// dimensions specify for what aspects the counter should be increased.
334        ///
335        /// For example, the quota "CPUs per region per VM family" enforces a limit
336        /// on the metric "compute.googleapis.com/cpus_per_vm_family" on dimensions
337        /// "region" and "vm_family". And if the violation occurred in region
338        /// "us-central1" and for VM family "n1", the quota_dimensions would be,
339        ///
340        /// {
341        /// "region": "us-central1",
342        /// "vm_family": "n1",
343        /// }
344        ///
345        /// When a quota is enforced globally, the quota_dimensions would always be
346        /// empty.
347        #[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
348        pub quota_dimensions: std::collections::HashMap<std::string::String, std::string::String>,
349
350        /// The enforced quota value at the time of the `QuotaFailure`.
351        ///
352        /// For example, if the enforced quota value at the time of the
353        /// `QuotaFailure` on the number of CPUs is "10", then the value of this
354        /// field would reflect this quantity.
355        #[serde_as(as = "serde_with::DisplayFromStr")]
356        pub quota_value: i64,
357
358        /// The new quota value being rolled out at the time of the violation. At the
359        /// completion of the rollout, this value will be enforced in place of
360        /// quota_value. If no rollout is in progress at the time of the violation,
361        /// this field is not set.
362        ///
363        /// For example, if at the time of the violation a rollout is in progress
364        /// changing the number of CPUs quota from 10 to 20, 20 would be the value of
365        /// this field.
366        #[serde(skip_serializing_if = "std::option::Option::is_none")]
367        #[serde_as(as = "std::option::Option<serde_with::DisplayFromStr>")]
368        pub future_quota_value: std::option::Option<i64>,
369
370        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
371        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
372    }
373
374    impl Violation {
375        pub fn new() -> Self {
376            std::default::Default::default()
377        }
378
379        /// Sets the value of [subject][crate::model::quota_failure::Violation::subject].
380        pub fn set_subject<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
381            self.subject = v.into();
382            self
383        }
384
385        /// Sets the value of [description][crate::model::quota_failure::Violation::description].
386        pub fn set_description<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
387            self.description = v.into();
388            self
389        }
390
391        /// Sets the value of [api_service][crate::model::quota_failure::Violation::api_service].
392        pub fn set_api_service<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
393            self.api_service = v.into();
394            self
395        }
396
397        /// Sets the value of [quota_metric][crate::model::quota_failure::Violation::quota_metric].
398        pub fn set_quota_metric<T: std::convert::Into<std::string::String>>(
399            mut self,
400            v: T,
401        ) -> Self {
402            self.quota_metric = v.into();
403            self
404        }
405
406        /// Sets the value of [quota_id][crate::model::quota_failure::Violation::quota_id].
407        pub fn set_quota_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
408            self.quota_id = v.into();
409            self
410        }
411
412        /// Sets the value of [quota_value][crate::model::quota_failure::Violation::quota_value].
413        pub fn set_quota_value<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
414            self.quota_value = v.into();
415            self
416        }
417
418        /// Sets the value of [future_quota_value][crate::model::quota_failure::Violation::future_quota_value].
419        pub fn set_future_quota_value<T: std::convert::Into<std::option::Option<i64>>>(
420            mut self,
421            v: T,
422        ) -> Self {
423            self.future_quota_value = v.into();
424            self
425        }
426
427        /// Sets the value of [quota_dimensions][crate::model::quota_failure::Violation::quota_dimensions].
428        pub fn set_quota_dimensions<T, K, V>(mut self, v: T) -> Self
429        where
430            T: std::iter::IntoIterator<Item = (K, V)>,
431            K: std::convert::Into<std::string::String>,
432            V: std::convert::Into<std::string::String>,
433        {
434            use std::iter::Iterator;
435            self.quota_dimensions = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
436            self
437        }
438    }
439
440    impl wkt::message::Message for Violation {
441        fn typename() -> &'static str {
442            "type.googleapis.com/google.rpc.QuotaFailure.Violation"
443        }
444    }
445}
446
447/// Describes what preconditions have failed.
448///
449/// For example, if an RPC failed because it required the Terms of Service to be
450/// acknowledged, it could list the terms of service violation in the
451/// PreconditionFailure message.
452#[serde_with::serde_as]
453#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
454#[serde(default, rename_all = "camelCase")]
455#[non_exhaustive]
456pub struct PreconditionFailure {
457    /// Describes all precondition violations.
458    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
459    pub violations: std::vec::Vec<crate::model::precondition_failure::Violation>,
460
461    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
462    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
463}
464
465impl PreconditionFailure {
466    pub fn new() -> Self {
467        std::default::Default::default()
468    }
469
470    /// Sets the value of [violations][crate::model::PreconditionFailure::violations].
471    pub fn set_violations<T, V>(mut self, v: T) -> Self
472    where
473        T: std::iter::IntoIterator<Item = V>,
474        V: std::convert::Into<crate::model::precondition_failure::Violation>,
475    {
476        use std::iter::Iterator;
477        self.violations = v.into_iter().map(|i| i.into()).collect();
478        self
479    }
480}
481
482impl wkt::message::Message for PreconditionFailure {
483    fn typename() -> &'static str {
484        "type.googleapis.com/google.rpc.PreconditionFailure"
485    }
486}
487
488/// Defines additional types related to [PreconditionFailure].
489pub mod precondition_failure {
490    #[allow(unused_imports)]
491    use super::*;
492
493    /// A message type used to describe a single precondition failure.
494    #[serde_with::serde_as]
495    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
496    #[serde(default, rename_all = "camelCase")]
497    #[non_exhaustive]
498    pub struct Violation {
499        /// The type of PreconditionFailure. We recommend using a service-specific
500        /// enum type to define the supported precondition violation subjects. For
501        /// example, "TOS" for "Terms of Service violation".
502        #[serde(rename = "type")]
503        #[serde(skip_serializing_if = "std::string::String::is_empty")]
504        pub r#type: std::string::String,
505
506        /// The subject, relative to the type, that failed.
507        /// For example, "google.com/cloud" relative to the "TOS" type would indicate
508        /// which terms of service is being referenced.
509        #[serde(skip_serializing_if = "std::string::String::is_empty")]
510        pub subject: std::string::String,
511
512        /// A description of how the precondition failed. Developers can use this
513        /// description to understand how to fix the failure.
514        ///
515        /// For example: "Terms of service not accepted".
516        #[serde(skip_serializing_if = "std::string::String::is_empty")]
517        pub description: std::string::String,
518
519        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
520        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
521    }
522
523    impl Violation {
524        pub fn new() -> Self {
525            std::default::Default::default()
526        }
527
528        /// Sets the value of [r#type][crate::model::precondition_failure::Violation::type].
529        pub fn set_type<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
530            self.r#type = v.into();
531            self
532        }
533
534        /// Sets the value of [subject][crate::model::precondition_failure::Violation::subject].
535        pub fn set_subject<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
536            self.subject = v.into();
537            self
538        }
539
540        /// Sets the value of [description][crate::model::precondition_failure::Violation::description].
541        pub fn set_description<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
542            self.description = v.into();
543            self
544        }
545    }
546
547    impl wkt::message::Message for Violation {
548        fn typename() -> &'static str {
549            "type.googleapis.com/google.rpc.PreconditionFailure.Violation"
550        }
551    }
552}
553
554/// Describes violations in a client request. This error type focuses on the
555/// syntactic aspects of the request.
556#[serde_with::serde_as]
557#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
558#[serde(default, rename_all = "camelCase")]
559#[non_exhaustive]
560pub struct BadRequest {
561    /// Describes all violations in a client request.
562    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
563    pub field_violations: std::vec::Vec<crate::model::bad_request::FieldViolation>,
564
565    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
566    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
567}
568
569impl BadRequest {
570    pub fn new() -> Self {
571        std::default::Default::default()
572    }
573
574    /// Sets the value of [field_violations][crate::model::BadRequest::field_violations].
575    pub fn set_field_violations<T, V>(mut self, v: T) -> Self
576    where
577        T: std::iter::IntoIterator<Item = V>,
578        V: std::convert::Into<crate::model::bad_request::FieldViolation>,
579    {
580        use std::iter::Iterator;
581        self.field_violations = v.into_iter().map(|i| i.into()).collect();
582        self
583    }
584}
585
586impl wkt::message::Message for BadRequest {
587    fn typename() -> &'static str {
588        "type.googleapis.com/google.rpc.BadRequest"
589    }
590}
591
592/// Defines additional types related to [BadRequest].
593pub mod bad_request {
594    #[allow(unused_imports)]
595    use super::*;
596
597    /// A message type used to describe a single bad request field.
598    #[serde_with::serde_as]
599    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
600    #[serde(default, rename_all = "camelCase")]
601    #[non_exhaustive]
602    pub struct FieldViolation {
603        /// A path that leads to a field in the request body. The value will be a
604        /// sequence of dot-separated identifiers that identify a protocol buffer
605        /// field.
606        ///
607        /// Consider the following:
608        ///
609        /// ```norust
610        /// message CreateContactRequest {
611        ///   message EmailAddress {
612        ///     enum Type {
613        ///       TYPE_UNSPECIFIED = 0;
614        ///       HOME = 1;
615        ///       WORK = 2;
616        ///     }
617        ///
618        ///     optional string email = 1;
619        ///     repeated EmailType type = 2;
620        ///   }
621        ///
622        ///   string full_name = 1;
623        ///   repeated EmailAddress email_addresses = 2;
624        /// }
625        /// ```
626        ///
627        /// In this example, in proto `field` could take one of the following values:
628        ///
629        /// * `full_name` for a violation in the `full_name` value
630        /// * `email_addresses[1].email` for a violation in the `email` field of the
631        ///   first `email_addresses` message
632        /// * `email_addresses[3].type[2]` for a violation in the second `type`
633        ///   value in the third `email_addresses` message.
634        ///
635        /// In JSON, the same values are represented as:
636        ///
637        /// * `fullName` for a violation in the `fullName` value
638        /// * `emailAddresses[1].email` for a violation in the `email` field of the
639        ///   first `emailAddresses` message
640        /// * `emailAddresses[3].type[2]` for a violation in the second `type`
641        ///   value in the third `emailAddresses` message.
642        #[serde(skip_serializing_if = "std::string::String::is_empty")]
643        pub field: std::string::String,
644
645        /// A description of why the request element is bad.
646        #[serde(skip_serializing_if = "std::string::String::is_empty")]
647        pub description: std::string::String,
648
649        /// The reason of the field-level error. This is a constant value that
650        /// identifies the proximate cause of the field-level error. It should
651        /// uniquely identify the type of the FieldViolation within the scope of the
652        /// google.rpc.ErrorInfo.domain. This should be at most 63
653        /// characters and match a regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`,
654        /// which represents UPPER_SNAKE_CASE.
655        #[serde(skip_serializing_if = "std::string::String::is_empty")]
656        pub reason: std::string::String,
657
658        /// Provides a localized error message for field-level errors that is safe to
659        /// return to the API consumer.
660        #[serde(skip_serializing_if = "std::option::Option::is_none")]
661        pub localized_message: std::option::Option<crate::model::LocalizedMessage>,
662
663        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
664        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
665    }
666
667    impl FieldViolation {
668        pub fn new() -> Self {
669            std::default::Default::default()
670        }
671
672        /// Sets the value of [field][crate::model::bad_request::FieldViolation::field].
673        pub fn set_field<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
674            self.field = v.into();
675            self
676        }
677
678        /// Sets the value of [description][crate::model::bad_request::FieldViolation::description].
679        pub fn set_description<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
680            self.description = v.into();
681            self
682        }
683
684        /// Sets the value of [reason][crate::model::bad_request::FieldViolation::reason].
685        pub fn set_reason<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
686            self.reason = v.into();
687            self
688        }
689
690        /// Sets the value of [localized_message][crate::model::bad_request::FieldViolation::localized_message].
691        pub fn set_localized_message<
692            T: std::convert::Into<std::option::Option<crate::model::LocalizedMessage>>,
693        >(
694            mut self,
695            v: T,
696        ) -> Self {
697            self.localized_message = v.into();
698            self
699        }
700    }
701
702    impl wkt::message::Message for FieldViolation {
703        fn typename() -> &'static str {
704            "type.googleapis.com/google.rpc.BadRequest.FieldViolation"
705        }
706    }
707}
708
709/// Contains metadata about the request that clients can attach when filing a bug
710/// or providing other forms of feedback.
711#[serde_with::serde_as]
712#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
713#[serde(default, rename_all = "camelCase")]
714#[non_exhaustive]
715pub struct RequestInfo {
716    /// An opaque string that should only be interpreted by the service generating
717    /// it. For example, it can be used to identify requests in the service's logs.
718    #[serde(skip_serializing_if = "std::string::String::is_empty")]
719    pub request_id: std::string::String,
720
721    /// Any data that was used to serve this request. For example, an encrypted
722    /// stack trace that can be sent back to the service provider for debugging.
723    #[serde(skip_serializing_if = "std::string::String::is_empty")]
724    pub serving_data: std::string::String,
725
726    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
727    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
728}
729
730impl RequestInfo {
731    pub fn new() -> Self {
732        std::default::Default::default()
733    }
734
735    /// Sets the value of [request_id][crate::model::RequestInfo::request_id].
736    pub fn set_request_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
737        self.request_id = v.into();
738        self
739    }
740
741    /// Sets the value of [serving_data][crate::model::RequestInfo::serving_data].
742    pub fn set_serving_data<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
743        self.serving_data = v.into();
744        self
745    }
746}
747
748impl wkt::message::Message for RequestInfo {
749    fn typename() -> &'static str {
750        "type.googleapis.com/google.rpc.RequestInfo"
751    }
752}
753
754/// Describes the resource that is being accessed.
755#[serde_with::serde_as]
756#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
757#[serde(default, rename_all = "camelCase")]
758#[non_exhaustive]
759pub struct ResourceInfo {
760    /// A name for the type of resource being accessed, e.g. "sql table",
761    /// "cloud storage bucket", "file", "Google calendar"; or the type URL
762    /// of the resource: e.g. "type.googleapis.com/google.pubsub.v1.Topic".
763    #[serde(skip_serializing_if = "std::string::String::is_empty")]
764    pub resource_type: std::string::String,
765
766    /// The name of the resource being accessed.  For example, a shared calendar
767    /// name: "example.com_4fghdhgsrgh@group.calendar.google.com", if the current
768    /// error is
769    /// [google.rpc.Code.PERMISSION_DENIED][google.rpc.Code.PERMISSION_DENIED].
770    ///
771    /// [google.rpc.Code.PERMISSION_DENIED]: crate::model::code::PERMISSION_DENIED
772    #[serde(skip_serializing_if = "std::string::String::is_empty")]
773    pub resource_name: std::string::String,
774
775    /// The owner of the resource (optional).
776    /// For example, "user:\<owner email\>" or "project:\<Google developer project
777    /// id\>".
778    #[serde(skip_serializing_if = "std::string::String::is_empty")]
779    pub owner: std::string::String,
780
781    /// Describes what error is encountered when accessing this resource.
782    /// For example, updating a cloud project may require the `writer` permission
783    /// on the developer console project.
784    #[serde(skip_serializing_if = "std::string::String::is_empty")]
785    pub description: std::string::String,
786
787    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
788    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
789}
790
791impl ResourceInfo {
792    pub fn new() -> Self {
793        std::default::Default::default()
794    }
795
796    /// Sets the value of [resource_type][crate::model::ResourceInfo::resource_type].
797    pub fn set_resource_type<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
798        self.resource_type = v.into();
799        self
800    }
801
802    /// Sets the value of [resource_name][crate::model::ResourceInfo::resource_name].
803    pub fn set_resource_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
804        self.resource_name = v.into();
805        self
806    }
807
808    /// Sets the value of [owner][crate::model::ResourceInfo::owner].
809    pub fn set_owner<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
810        self.owner = v.into();
811        self
812    }
813
814    /// Sets the value of [description][crate::model::ResourceInfo::description].
815    pub fn set_description<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
816        self.description = v.into();
817        self
818    }
819}
820
821impl wkt::message::Message for ResourceInfo {
822    fn typename() -> &'static str {
823        "type.googleapis.com/google.rpc.ResourceInfo"
824    }
825}
826
827/// Provides links to documentation or for performing an out of band action.
828///
829/// For example, if a quota check failed with an error indicating the calling
830/// project hasn't enabled the accessed service, this can contain a URL pointing
831/// directly to the right place in the developer console to flip the bit.
832#[serde_with::serde_as]
833#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
834#[serde(default, rename_all = "camelCase")]
835#[non_exhaustive]
836pub struct Help {
837    /// URL(s) pointing to additional information on handling the current error.
838    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
839    pub links: std::vec::Vec<crate::model::help::Link>,
840
841    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
842    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
843}
844
845impl Help {
846    pub fn new() -> Self {
847        std::default::Default::default()
848    }
849
850    /// Sets the value of [links][crate::model::Help::links].
851    pub fn set_links<T, V>(mut self, v: T) -> Self
852    where
853        T: std::iter::IntoIterator<Item = V>,
854        V: std::convert::Into<crate::model::help::Link>,
855    {
856        use std::iter::Iterator;
857        self.links = v.into_iter().map(|i| i.into()).collect();
858        self
859    }
860}
861
862impl wkt::message::Message for Help {
863    fn typename() -> &'static str {
864        "type.googleapis.com/google.rpc.Help"
865    }
866}
867
868/// Defines additional types related to [Help].
869pub mod help {
870    #[allow(unused_imports)]
871    use super::*;
872
873    /// Describes a URL link.
874    #[serde_with::serde_as]
875    #[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
876    #[serde(default, rename_all = "camelCase")]
877    #[non_exhaustive]
878    pub struct Link {
879        /// Describes what the link offers.
880        #[serde(skip_serializing_if = "std::string::String::is_empty")]
881        pub description: std::string::String,
882
883        /// The URL of the link.
884        #[serde(skip_serializing_if = "std::string::String::is_empty")]
885        pub url: std::string::String,
886
887        #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
888        _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
889    }
890
891    impl Link {
892        pub fn new() -> Self {
893            std::default::Default::default()
894        }
895
896        /// Sets the value of [description][crate::model::help::Link::description].
897        pub fn set_description<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
898            self.description = v.into();
899            self
900        }
901
902        /// Sets the value of [url][crate::model::help::Link::url].
903        pub fn set_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
904            self.url = v.into();
905            self
906        }
907    }
908
909    impl wkt::message::Message for Link {
910        fn typename() -> &'static str {
911            "type.googleapis.com/google.rpc.Help.Link"
912        }
913    }
914}
915
916/// Provides a localized error message that is safe to return to the user
917/// which can be attached to an RPC error.
918#[serde_with::serde_as]
919#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
920#[serde(default, rename_all = "camelCase")]
921#[non_exhaustive]
922pub struct LocalizedMessage {
923    /// The locale used following the specification defined at
924    /// <https://www.rfc-editor.org/rfc/bcp/bcp47.txt>.
925    /// Examples are: "en-US", "fr-CH", "es-MX"
926    #[serde(skip_serializing_if = "std::string::String::is_empty")]
927    pub locale: std::string::String,
928
929    /// The localized error message in the above locale.
930    #[serde(skip_serializing_if = "std::string::String::is_empty")]
931    pub message: std::string::String,
932
933    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
934    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
935}
936
937impl LocalizedMessage {
938    pub fn new() -> Self {
939        std::default::Default::default()
940    }
941
942    /// Sets the value of [locale][crate::model::LocalizedMessage::locale].
943    pub fn set_locale<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
944        self.locale = v.into();
945        self
946    }
947
948    /// Sets the value of [message][crate::model::LocalizedMessage::message].
949    pub fn set_message<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
950        self.message = v.into();
951        self
952    }
953}
954
955impl wkt::message::Message for LocalizedMessage {
956    fn typename() -> &'static str {
957        "type.googleapis.com/google.rpc.LocalizedMessage"
958    }
959}
960
961/// Represents an HTTP request.
962#[serde_with::serde_as]
963#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
964#[serde(default, rename_all = "camelCase")]
965#[non_exhaustive]
966pub struct HttpRequest {
967    /// The HTTP request method.
968    #[serde(skip_serializing_if = "std::string::String::is_empty")]
969    pub method: std::string::String,
970
971    /// The HTTP request URI.
972    #[serde(skip_serializing_if = "std::string::String::is_empty")]
973    pub uri: std::string::String,
974
975    /// The HTTP request headers. The ordering of the headers is significant.
976    /// Multiple headers with the same key may present for the request.
977    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
978    pub headers: std::vec::Vec<crate::model::HttpHeader>,
979
980    /// The HTTP request body. If the body is not expected, it should be empty.
981    #[serde(skip_serializing_if = "::bytes::Bytes::is_empty")]
982    #[serde_as(as = "serde_with::base64::Base64")]
983    pub body: ::bytes::Bytes,
984
985    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
986    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
987}
988
989impl HttpRequest {
990    pub fn new() -> Self {
991        std::default::Default::default()
992    }
993
994    /// Sets the value of [method][crate::model::HttpRequest::method].
995    pub fn set_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
996        self.method = v.into();
997        self
998    }
999
1000    /// Sets the value of [uri][crate::model::HttpRequest::uri].
1001    pub fn set_uri<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1002        self.uri = v.into();
1003        self
1004    }
1005
1006    /// Sets the value of [body][crate::model::HttpRequest::body].
1007    pub fn set_body<T: std::convert::Into<::bytes::Bytes>>(mut self, v: T) -> Self {
1008        self.body = v.into();
1009        self
1010    }
1011
1012    /// Sets the value of [headers][crate::model::HttpRequest::headers].
1013    pub fn set_headers<T, V>(mut self, v: T) -> Self
1014    where
1015        T: std::iter::IntoIterator<Item = V>,
1016        V: std::convert::Into<crate::model::HttpHeader>,
1017    {
1018        use std::iter::Iterator;
1019        self.headers = v.into_iter().map(|i| i.into()).collect();
1020        self
1021    }
1022}
1023
1024impl wkt::message::Message for HttpRequest {
1025    fn typename() -> &'static str {
1026        "type.googleapis.com/google.rpc.HttpRequest"
1027    }
1028}
1029
1030/// Represents an HTTP response.
1031#[serde_with::serde_as]
1032#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1033#[serde(default, rename_all = "camelCase")]
1034#[non_exhaustive]
1035pub struct HttpResponse {
1036    /// The HTTP status code, such as 200 or 404.
1037    pub status: i32,
1038
1039    /// The HTTP reason phrase, such as "OK" or "Not Found".
1040    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1041    pub reason: std::string::String,
1042
1043    /// The HTTP response headers. The ordering of the headers is significant.
1044    /// Multiple headers with the same key may present for the response.
1045    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1046    pub headers: std::vec::Vec<crate::model::HttpHeader>,
1047
1048    /// The HTTP response body. If the body is not expected, it should be empty.
1049    #[serde(skip_serializing_if = "::bytes::Bytes::is_empty")]
1050    #[serde_as(as = "serde_with::base64::Base64")]
1051    pub body: ::bytes::Bytes,
1052
1053    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1054    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1055}
1056
1057impl HttpResponse {
1058    pub fn new() -> Self {
1059        std::default::Default::default()
1060    }
1061
1062    /// Sets the value of [status][crate::model::HttpResponse::status].
1063    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
1064        self.status = v.into();
1065        self
1066    }
1067
1068    /// Sets the value of [reason][crate::model::HttpResponse::reason].
1069    pub fn set_reason<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1070        self.reason = v.into();
1071        self
1072    }
1073
1074    /// Sets the value of [body][crate::model::HttpResponse::body].
1075    pub fn set_body<T: std::convert::Into<::bytes::Bytes>>(mut self, v: T) -> Self {
1076        self.body = v.into();
1077        self
1078    }
1079
1080    /// Sets the value of [headers][crate::model::HttpResponse::headers].
1081    pub fn set_headers<T, V>(mut self, v: T) -> Self
1082    where
1083        T: std::iter::IntoIterator<Item = V>,
1084        V: std::convert::Into<crate::model::HttpHeader>,
1085    {
1086        use std::iter::Iterator;
1087        self.headers = v.into_iter().map(|i| i.into()).collect();
1088        self
1089    }
1090}
1091
1092impl wkt::message::Message for HttpResponse {
1093    fn typename() -> &'static str {
1094        "type.googleapis.com/google.rpc.HttpResponse"
1095    }
1096}
1097
1098/// Represents an HTTP header.
1099#[serde_with::serde_as]
1100#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1101#[serde(default, rename_all = "camelCase")]
1102#[non_exhaustive]
1103pub struct HttpHeader {
1104    /// The HTTP header key. It is case insensitive.
1105    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1106    pub key: std::string::String,
1107
1108    /// The HTTP header value.
1109    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1110    pub value: std::string::String,
1111
1112    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1113    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1114}
1115
1116impl HttpHeader {
1117    pub fn new() -> Self {
1118        std::default::Default::default()
1119    }
1120
1121    /// Sets the value of [key][crate::model::HttpHeader::key].
1122    pub fn set_key<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1123        self.key = v.into();
1124        self
1125    }
1126
1127    /// Sets the value of [value][crate::model::HttpHeader::value].
1128    pub fn set_value<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1129        self.value = v.into();
1130        self
1131    }
1132}
1133
1134impl wkt::message::Message for HttpHeader {
1135    fn typename() -> &'static str {
1136        "type.googleapis.com/google.rpc.HttpHeader"
1137    }
1138}
1139
1140/// The `Status` type defines a logical error model that is suitable for
1141/// different programming environments, including REST APIs and RPC APIs. It is
1142/// used by [gRPC](https://github.com/grpc). Each `Status` message contains
1143/// three pieces of data: error code, error message, and error details.
1144///
1145/// You can find out more about this error model and how to work with it in the
1146/// [API Design Guide](https://cloud.google.com/apis/design/errors).
1147#[serde_with::serde_as]
1148#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
1149#[serde(default, rename_all = "camelCase")]
1150#[non_exhaustive]
1151pub struct Status {
1152    /// The status code, which should be an enum value of
1153    /// [google.rpc.Code][google.rpc.Code].
1154    ///
1155    /// [google.rpc.Code]: crate::model::Code
1156    pub code: i32,
1157
1158    /// A developer-facing error message, which should be in English. Any
1159    /// user-facing error message should be localized and sent in the
1160    /// [google.rpc.Status.details][google.rpc.Status.details] field, or localized
1161    /// by the client.
1162    ///
1163    /// [google.rpc.Status.details]: crate::model::Status::details
1164    #[serde(skip_serializing_if = "std::string::String::is_empty")]
1165    pub message: std::string::String,
1166
1167    /// A list of messages that carry the error details.  There is a common set of
1168    /// message types for APIs to use.
1169    #[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
1170    pub details: std::vec::Vec<wkt::Any>,
1171
1172    #[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
1173    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
1174}
1175
1176impl Status {
1177    pub fn new() -> Self {
1178        std::default::Default::default()
1179    }
1180
1181    /// Sets the value of [code][crate::model::Status::code].
1182    pub fn set_code<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
1183        self.code = v.into();
1184        self
1185    }
1186
1187    /// Sets the value of [message][crate::model::Status::message].
1188    pub fn set_message<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
1189        self.message = v.into();
1190        self
1191    }
1192
1193    /// Sets the value of [details][crate::model::Status::details].
1194    pub fn set_details<T, V>(mut self, v: T) -> Self
1195    where
1196        T: std::iter::IntoIterator<Item = V>,
1197        V: std::convert::Into<wkt::Any>,
1198    {
1199        use std::iter::Iterator;
1200        self.details = v.into_iter().map(|i| i.into()).collect();
1201        self
1202    }
1203}
1204
1205impl wkt::message::Message for Status {
1206    fn typename() -> &'static str {
1207        "type.googleapis.com/google.rpc.Status"
1208    }
1209}
1210
1211/// The canonical error codes for gRPC APIs.
1212///
1213/// Sometimes multiple error codes may apply.  Services should return
1214/// the most specific error code that applies.  For example, prefer
1215/// `OUT_OF_RANGE` over `FAILED_PRECONDITION` if both codes apply.
1216/// Similarly prefer `NOT_FOUND` or `ALREADY_EXISTS` over `FAILED_PRECONDITION`.
1217#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
1218pub struct Code(i32);
1219
1220impl Code {
1221    /// Not an error; returned on success.
1222    ///
1223    /// HTTP Mapping: 200 OK
1224    pub const OK: Code = Code::new(0);
1225
1226    /// The operation was cancelled, typically by the caller.
1227    ///
1228    /// HTTP Mapping: 499 Client Closed Request
1229    pub const CANCELLED: Code = Code::new(1);
1230
1231    /// Unknown error.  For example, this error may be returned when
1232    /// a `Status` value received from another address space belongs to
1233    /// an error space that is not known in this address space.  Also
1234    /// errors raised by APIs that do not return enough error information
1235    /// may be converted to this error.
1236    ///
1237    /// HTTP Mapping: 500 Internal Server Error
1238    pub const UNKNOWN: Code = Code::new(2);
1239
1240    /// The client specified an invalid argument.  Note that this differs
1241    /// from `FAILED_PRECONDITION`.  `INVALID_ARGUMENT` indicates arguments
1242    /// that are problematic regardless of the state of the system
1243    /// (e.g., a malformed file name).
1244    ///
1245    /// HTTP Mapping: 400 Bad Request
1246    pub const INVALID_ARGUMENT: Code = Code::new(3);
1247
1248    /// The deadline expired before the operation could complete. For operations
1249    /// that change the state of the system, this error may be returned
1250    /// even if the operation has completed successfully.  For example, a
1251    /// successful response from a server could have been delayed long
1252    /// enough for the deadline to expire.
1253    ///
1254    /// HTTP Mapping: 504 Gateway Timeout
1255    pub const DEADLINE_EXCEEDED: Code = Code::new(4);
1256
1257    /// Some requested entity (e.g., file or directory) was not found.
1258    ///
1259    /// Note to server developers: if a request is denied for an entire class
1260    /// of users, such as gradual feature rollout or undocumented allowlist,
1261    /// `NOT_FOUND` may be used. If a request is denied for some users within
1262    /// a class of users, such as user-based access control, `PERMISSION_DENIED`
1263    /// must be used.
1264    ///
1265    /// HTTP Mapping: 404 Not Found
1266    pub const NOT_FOUND: Code = Code::new(5);
1267
1268    /// The entity that a client attempted to create (e.g., file or directory)
1269    /// already exists.
1270    ///
1271    /// HTTP Mapping: 409 Conflict
1272    pub const ALREADY_EXISTS: Code = Code::new(6);
1273
1274    /// The caller does not have permission to execute the specified
1275    /// operation. `PERMISSION_DENIED` must not be used for rejections
1276    /// caused by exhausting some resource (use `RESOURCE_EXHAUSTED`
1277    /// instead for those errors). `PERMISSION_DENIED` must not be
1278    /// used if the caller can not be identified (use `UNAUTHENTICATED`
1279    /// instead for those errors). This error code does not imply the
1280    /// request is valid or the requested entity exists or satisfies
1281    /// other pre-conditions.
1282    ///
1283    /// HTTP Mapping: 403 Forbidden
1284    pub const PERMISSION_DENIED: Code = Code::new(7);
1285
1286    /// The request does not have valid authentication credentials for the
1287    /// operation.
1288    ///
1289    /// HTTP Mapping: 401 Unauthorized
1290    pub const UNAUTHENTICATED: Code = Code::new(16);
1291
1292    /// Some resource has been exhausted, perhaps a per-user quota, or
1293    /// perhaps the entire file system is out of space.
1294    ///
1295    /// HTTP Mapping: 429 Too Many Requests
1296    pub const RESOURCE_EXHAUSTED: Code = Code::new(8);
1297
1298    /// The operation was rejected because the system is not in a state
1299    /// required for the operation's execution.  For example, the directory
1300    /// to be deleted is non-empty, an rmdir operation is applied to
1301    /// a non-directory, etc.
1302    ///
1303    /// Service implementors can use the following guidelines to decide
1304    /// between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`:
1305    /// (a) Use `UNAVAILABLE` if the client can retry just the failing call.
1306    /// (b) Use `ABORTED` if the client should retry at a higher level. For
1307    /// example, when a client-specified test-and-set fails, indicating the
1308    /// client should restart a read-modify-write sequence.
1309    /// (c) Use `FAILED_PRECONDITION` if the client should not retry until
1310    /// the system state has been explicitly fixed. For example, if an "rmdir"
1311    /// fails because the directory is non-empty, `FAILED_PRECONDITION`
1312    /// should be returned since the client should not retry unless
1313    /// the files are deleted from the directory.
1314    ///
1315    /// HTTP Mapping: 400 Bad Request
1316    pub const FAILED_PRECONDITION: Code = Code::new(9);
1317
1318    /// The operation was aborted, typically due to a concurrency issue such as
1319    /// a sequencer check failure or transaction abort.
1320    ///
1321    /// See the guidelines above for deciding between `FAILED_PRECONDITION`,
1322    /// `ABORTED`, and `UNAVAILABLE`.
1323    ///
1324    /// HTTP Mapping: 409 Conflict
1325    pub const ABORTED: Code = Code::new(10);
1326
1327    /// The operation was attempted past the valid range.  E.g., seeking or
1328    /// reading past end-of-file.
1329    ///
1330    /// Unlike `INVALID_ARGUMENT`, this error indicates a problem that may
1331    /// be fixed if the system state changes. For example, a 32-bit file
1332    /// system will generate `INVALID_ARGUMENT` if asked to read at an
1333    /// offset that is not in the range [0,2^32-1], but it will generate
1334    /// `OUT_OF_RANGE` if asked to read from an offset past the current
1335    /// file size.
1336    ///
1337    /// There is a fair bit of overlap between `FAILED_PRECONDITION` and
1338    /// `OUT_OF_RANGE`.  We recommend using `OUT_OF_RANGE` (the more specific
1339    /// error) when it applies so that callers who are iterating through
1340    /// a space can easily look for an `OUT_OF_RANGE` error to detect when
1341    /// they are done.
1342    ///
1343    /// HTTP Mapping: 400 Bad Request
1344    pub const OUT_OF_RANGE: Code = Code::new(11);
1345
1346    /// The operation is not implemented or is not supported/enabled in this
1347    /// service.
1348    ///
1349    /// HTTP Mapping: 501 Not Implemented
1350    pub const UNIMPLEMENTED: Code = Code::new(12);
1351
1352    /// Internal errors.  This means that some invariants expected by the
1353    /// underlying system have been broken.  This error code is reserved
1354    /// for serious errors.
1355    ///
1356    /// HTTP Mapping: 500 Internal Server Error
1357    pub const INTERNAL: Code = Code::new(13);
1358
1359    /// The service is currently unavailable.  This is most likely a
1360    /// transient condition, which can be corrected by retrying with
1361    /// a backoff. Note that it is not always safe to retry
1362    /// non-idempotent operations.
1363    ///
1364    /// See the guidelines above for deciding between `FAILED_PRECONDITION`,
1365    /// `ABORTED`, and `UNAVAILABLE`.
1366    ///
1367    /// HTTP Mapping: 503 Service Unavailable
1368    pub const UNAVAILABLE: Code = Code::new(14);
1369
1370    /// Unrecoverable data loss or corruption.
1371    ///
1372    /// HTTP Mapping: 500 Internal Server Error
1373    pub const DATA_LOSS: Code = Code::new(15);
1374
1375    /// Creates a new Code instance.
1376    pub(crate) const fn new(value: i32) -> Self {
1377        Self(value)
1378    }
1379
1380    /// Gets the enum value.
1381    pub fn value(&self) -> i32 {
1382        self.0
1383    }
1384
1385    /// Gets the enum value as a string.
1386    pub fn as_str_name(&self) -> std::borrow::Cow<'static, str> {
1387        match self.0 {
1388            0 => std::borrow::Cow::Borrowed("OK"),
1389            1 => std::borrow::Cow::Borrowed("CANCELLED"),
1390            2 => std::borrow::Cow::Borrowed("UNKNOWN"),
1391            3 => std::borrow::Cow::Borrowed("INVALID_ARGUMENT"),
1392            4 => std::borrow::Cow::Borrowed("DEADLINE_EXCEEDED"),
1393            5 => std::borrow::Cow::Borrowed("NOT_FOUND"),
1394            6 => std::borrow::Cow::Borrowed("ALREADY_EXISTS"),
1395            7 => std::borrow::Cow::Borrowed("PERMISSION_DENIED"),
1396            8 => std::borrow::Cow::Borrowed("RESOURCE_EXHAUSTED"),
1397            9 => std::borrow::Cow::Borrowed("FAILED_PRECONDITION"),
1398            10 => std::borrow::Cow::Borrowed("ABORTED"),
1399            11 => std::borrow::Cow::Borrowed("OUT_OF_RANGE"),
1400            12 => std::borrow::Cow::Borrowed("UNIMPLEMENTED"),
1401            13 => std::borrow::Cow::Borrowed("INTERNAL"),
1402            14 => std::borrow::Cow::Borrowed("UNAVAILABLE"),
1403            15 => std::borrow::Cow::Borrowed("DATA_LOSS"),
1404            16 => std::borrow::Cow::Borrowed("UNAUTHENTICATED"),
1405            _ => std::borrow::Cow::Owned(std::format!("UNKNOWN-VALUE:{}", self.0)),
1406        }
1407    }
1408
1409    /// Creates an enum value from the value name.
1410    pub fn from_str_name(name: &str) -> std::option::Option<Self> {
1411        match name {
1412            "OK" => std::option::Option::Some(Self::OK),
1413            "CANCELLED" => std::option::Option::Some(Self::CANCELLED),
1414            "UNKNOWN" => std::option::Option::Some(Self::UNKNOWN),
1415            "INVALID_ARGUMENT" => std::option::Option::Some(Self::INVALID_ARGUMENT),
1416            "DEADLINE_EXCEEDED" => std::option::Option::Some(Self::DEADLINE_EXCEEDED),
1417            "NOT_FOUND" => std::option::Option::Some(Self::NOT_FOUND),
1418            "ALREADY_EXISTS" => std::option::Option::Some(Self::ALREADY_EXISTS),
1419            "PERMISSION_DENIED" => std::option::Option::Some(Self::PERMISSION_DENIED),
1420            "UNAUTHENTICATED" => std::option::Option::Some(Self::UNAUTHENTICATED),
1421            "RESOURCE_EXHAUSTED" => std::option::Option::Some(Self::RESOURCE_EXHAUSTED),
1422            "FAILED_PRECONDITION" => std::option::Option::Some(Self::FAILED_PRECONDITION),
1423            "ABORTED" => std::option::Option::Some(Self::ABORTED),
1424            "OUT_OF_RANGE" => std::option::Option::Some(Self::OUT_OF_RANGE),
1425            "UNIMPLEMENTED" => std::option::Option::Some(Self::UNIMPLEMENTED),
1426            "INTERNAL" => std::option::Option::Some(Self::INTERNAL),
1427            "UNAVAILABLE" => std::option::Option::Some(Self::UNAVAILABLE),
1428            "DATA_LOSS" => std::option::Option::Some(Self::DATA_LOSS),
1429            _ => std::option::Option::None,
1430        }
1431    }
1432}
1433
1434impl std::convert::From<i32> for Code {
1435    fn from(value: i32) -> Self {
1436        Self::new(value)
1437    }
1438}
1439
1440impl std::default::Default for Code {
1441    fn default() -> Self {
1442        Self::new(0)
1443    }
1444}