iota_grpc_types/proto/
google.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2025 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5#[allow(rustdoc::invalid_html_tags)]
6pub mod rpc {
7    include!("generated/google.rpc.rs");
8
9    impl ::prost::Name for Status {
10        const NAME: &'static str = "Status";
11        const PACKAGE: &'static str = "google.rpc";
12        fn full_name() -> ::prost::alloc::string::String {
13            "google.rpc.Status".into()
14        }
15        fn type_url() -> ::prost::alloc::string::String {
16            "/google.rpc.Status".into()
17        }
18    }
19
20    impl Status {
21        /// Convert to a [`tonic::Status`], preserving code, message, and
22        /// details.
23        ///
24        /// The details are encoded as the binary `google.rpc.Status` message,
25        /// matching the `grpc-status-details-bin` trailer convention.
26        pub fn to_tonic_status(&self) -> tonic::Status {
27            use prost::Message;
28
29            let code = tonic::Code::from_i32(self.code);
30            let details_bytes = self.encode_to_vec();
31            tonic::Status::with_details(code, &self.message, details_bytes.into())
32        }
33    }
34
35    impl ::prost::Name for ErrorInfo {
36        const NAME: &'static str = "ErrorInfo";
37        const PACKAGE: &'static str = "google.rpc";
38        fn full_name() -> ::prost::alloc::string::String {
39            "google.rpc.ErrorInfo".into()
40        }
41        fn type_url() -> ::prost::alloc::string::String {
42            "/google.rpc.ErrorInfo".into()
43        }
44    }
45
46    impl ::prost::Name for RetryInfo {
47        const NAME: &'static str = "RetryInfo";
48        const PACKAGE: &'static str = "google.rpc";
49        fn full_name() -> ::prost::alloc::string::String {
50            "google.rpc.RetryInfo".into()
51        }
52        fn type_url() -> ::prost::alloc::string::String {
53            "/google.rpc.RetryInfo".into()
54        }
55    }
56
57    impl ::prost::Name for DebugInfo {
58        const NAME: &'static str = "DebugInfo";
59        const PACKAGE: &'static str = "google.rpc";
60        fn full_name() -> ::prost::alloc::string::String {
61            "google.rpc.DebugInfo".into()
62        }
63        fn type_url() -> ::prost::alloc::string::String {
64            "/google.rpc.DebugInfo".into()
65        }
66    }
67
68    impl ::prost::Name for QuotaFailure {
69        const NAME: &'static str = "QuotaFailure";
70        const PACKAGE: &'static str = "google.rpc";
71        fn full_name() -> ::prost::alloc::string::String {
72            "google.rpc.QuotaFailure".into()
73        }
74        fn type_url() -> ::prost::alloc::string::String {
75            "/google.rpc.QuotaFailure".into()
76        }
77    }
78
79    impl ::prost::Name for PreconditionFailure {
80        const NAME: &'static str = "PreconditionFailure";
81        const PACKAGE: &'static str = "google.rpc";
82        fn full_name() -> ::prost::alloc::string::String {
83            "google.rpc.PreconditionFailure".into()
84        }
85        fn type_url() -> ::prost::alloc::string::String {
86            "/google.rpc.PreconditionFailure".into()
87        }
88    }
89
90    impl ::prost::Name for BadRequest {
91        const NAME: &'static str = "BadRequest";
92        const PACKAGE: &'static str = "google.rpc";
93        fn full_name() -> ::prost::alloc::string::String {
94            "google.rpc.BadRequest".into()
95        }
96        fn type_url() -> ::prost::alloc::string::String {
97            "/google.rpc.BadRequest".into()
98        }
99    }
100
101    impl bad_request::FieldViolation {
102        pub fn new<T: Into<String>>(field: T) -> Self {
103            Self {
104                field: field.into(),
105                ..Default::default()
106            }
107        }
108
109        pub fn new_at<T: Into<String>>(field: T, index: usize) -> Self {
110            use std::fmt::Write;
111
112            let mut field = field.into();
113            write!(&mut field, "[{index}]").expect("write to String cannot fail");
114
115            Self {
116                field,
117                ..Default::default()
118            }
119        }
120
121        pub fn with_description<T: Into<String>>(mut self, description: T) -> Self {
122            self.description = description.into();
123            self
124        }
125
126        pub fn with_reason<T: Into<String>>(mut self, reason: T) -> Self {
127            self.reason = reason.into();
128            self
129        }
130
131        pub fn nested<T: Into<String>>(mut self, field: T) -> Self {
132            use std::fmt::Write;
133
134            let mut field = field.into();
135
136            if !self.field.is_empty() {
137                write!(
138                    &mut field,
139                    "{}{}",
140                    crate::field::FIELD_SEPARATOR,
141                    self.field
142                )
143                .expect("write to String cannot fail");
144            }
145
146            self.field = field;
147            self
148        }
149
150        pub fn nested_at<T: Into<String>>(mut self, field: T, index: usize) -> Self {
151            use std::fmt::Write;
152
153            let mut field = field.into();
154            write!(&mut field, "[{index}]").expect("write to String cannot fail");
155
156            if !self.field.is_empty() {
157                write!(
158                    &mut field,
159                    "{}{}",
160                    crate::field::FIELD_SEPARATOR,
161                    self.field
162                )
163                .expect("write to String cannot fail");
164            }
165
166            self.field = field;
167            self
168        }
169    }
170
171    impl From<bad_request::FieldViolation> for BadRequest {
172        fn from(value: bad_request::FieldViolation) -> Self {
173            Self {
174                field_violations: vec![value],
175            }
176        }
177    }
178
179    impl BadRequest {
180        pub fn nested<T: AsRef<str>>(mut self, field: T) -> Self {
181            let field = field.as_ref();
182            self.field_violations = self
183                .field_violations
184                .into_iter()
185                .map(|violation| violation.nested(field))
186                .collect();
187            self
188        }
189
190        pub fn nested_at<T: AsRef<str>>(mut self, field: T, index: usize) -> Self {
191            let field = field.as_ref();
192            self.field_violations = self
193                .field_violations
194                .into_iter()
195                .map(|violation| violation.nested_at(field, index))
196                .collect();
197            self
198        }
199    }
200
201    impl ::prost::Name for RequestInfo {
202        const NAME: &'static str = "RequestInfo";
203        const PACKAGE: &'static str = "google.rpc";
204        fn full_name() -> ::prost::alloc::string::String {
205            "google.rpc.RequestInfo".into()
206        }
207        fn type_url() -> ::prost::alloc::string::String {
208            "/google.rpc.RequestInfo".into()
209        }
210    }
211
212    impl ::prost::Name for ResourceInfo {
213        const NAME: &'static str = "ResourceInfo";
214        const PACKAGE: &'static str = "google.rpc";
215        fn full_name() -> ::prost::alloc::string::String {
216            "google.rpc.ResourceInfo".into()
217        }
218        fn type_url() -> ::prost::alloc::string::String {
219            "/google.rpc.ResourceInfo".into()
220        }
221    }
222}