1use proto_types::{Any, Code, Duration, Empty, FieldMask, Status, Timestamp};
2
3use crate::*;
4
5impl_known_type!(target = Status, package = "google.rpc");
6impl_known_type!(target = Code, package = "google.rpc", type_ = Enum);
7
8impl_known_type!(target = Empty, package = "google.protobuf");
9type Unit = ();
10impl_known_type!(target = Unit, package = "google.protobuf", name = "Empty");
11
12impl_known_type!(
13 target = Duration,
14 impl_validator = false,
15 package = "google.protobuf"
16);
17impl_known_type!(
18 target = Timestamp,
19 impl_validator = false,
20 package = "google.protobuf"
21);
22impl_known_type!(
23 target = FieldMask,
24 impl_validator = false,
25 package = "google.protobuf"
26);
27impl_known_type!(
28 target = Any,
29 impl_validator = false,
30 package = "google.protobuf"
31);
32
33#[doc(hidden)]
34#[derive(Clone, Copy, Default)]
35pub struct NoOpValidator<T: ?Sized>(PhantomData<T>);
36
37impl<T: ?Sized + Send + Sync + ToOwned> Validator<T> for NoOpValidator<T> {
38 type Target = T;
39
40 #[doc(hidden)]
41 #[inline(always)]
42 fn execute_validation(
43 &self,
44 _ctx: &mut ValidationCtx,
45 _val: Option<&Self::Target>,
46 ) -> ValidationResult {
47 Ok(IsValid::Yes)
48 }
49}
50
51#[doc(hidden)]
52pub struct NoOpValidatorBuilder<T: ?Sized>(PhantomData<T>);
53
54impl<T: ?Sized> Default for NoOpValidatorBuilder<T> {
55 #[inline(always)]
56 fn default() -> Self {
57 Self(Default::default())
58 }
59}
60
61impl<T> ValidatorBuilderFor<T> for NoOpValidatorBuilder<T>
62where
63 T: ?Sized + Send + Sync + ToOwned,
64{
65 type Validator = NoOpValidator<T>;
66 #[inline(always)]
67 fn build_validator(self) -> Self::Validator {
68 NoOpValidator(PhantomData)
69 }
70}
71
72#[cfg(feature = "common-types")]
73mod google_dot_type {
74 use super::*;
75 use proto_types::*;
76
77 macro_rules! impl_types {
78 ($($name:ident),*) => {
79 $(
80 impl_known_type!(target = $name, package = "google.type");
81 )*
82 };
83 }
84
85 impl_types!(
86 Date,
87 Interval,
88 Money,
89 Color,
90 Fraction,
91 Decimal,
92 PostalAddress,
93 PhoneNumber,
94 Quaternion,
95 LocalizedText,
96 Expr
97 );
98
99 impl_known_type!(
100 target = DateTime,
101 package = "google.type",
102 file = "google/type/datetime.proto"
103 );
104 impl_known_type!(
105 target = TimeZone,
106 package = "google.type",
107 file = "google/type/datetime.proto"
108 );
109 impl_known_type!(
110 target = LatLng,
111 package = "google.type",
112 file = "google/type/latlng.proto"
113 );
114 impl_known_type!(
115 target = TimeOfDay,
116 package = "google.type",
117 file = "google/type/timeofday.proto"
118 );
119 impl_known_type!(
120 target = CalendarPeriod,
121 package = "google.type",
122 type_ = Enum
123 );
124 impl_known_type!(target = Month, package = "google.type", type_ = Enum);
125 impl_known_type!(
126 target = DayOfWeek,
127 package = "google.type",
128 type_ = Enum,
129 file = "google/type/dayofweek.proto"
130 );
131}
132
133#[cfg(feature = "rpc-types")]
134mod rpc_types {
135 use super::*;
136 use proto_types::{
137 bad_request::FieldViolation, help::Link,
138 precondition_failure::Violation as PreconditionViolation,
139 quota_failure::Violation as QuotaFailureViolation, *,
140 };
141
142 macro_rules! impl_types {
143 ($($name:ident),*) => {
144 $(
145 impl_known_type!(target = $name, package = "google.rpc", file = "google/rpc/error_details.proto");
146 )*
147 };
148 }
149
150 impl_types!(
151 ErrorInfo,
152 DebugInfo,
153 RetryInfo,
154 QuotaFailure,
155 PreconditionFailure,
156 BadRequest,
157 RequestInfo,
158 ResourceInfo,
159 Help,
160 LocalizedMessage
161 );
162
163 impl_known_type!(
164 target = HttpRequest,
165 package = "google.rpc",
166 file = "google/rpc/http.proto"
167 );
168 impl_known_type!(
169 target = HttpResponse,
170 package = "google.rpc",
171 file = "google/rpc/http.proto"
172 );
173 impl_known_type!(
174 target = HttpHeader,
175 package = "google.rpc",
176 file = "google/rpc/http.proto",
177 store = hybrid
178 );
179
180 impl_known_type!(
181 target = QuotaFailureViolation,
182 name = "QuotaFailure.Violation",
183 package = "google.rpc",
184 file = "google/rpc/error_details.proto"
185 );
186
187 impl_known_type!(
188 target = PreconditionViolation,
189 name = "PreconditionFailure.Violation",
190 package = "google.rpc",
191 file = "google/rpc/error_details.proto"
192 );
193
194 impl_known_type!(
195 target = FieldViolation,
196 name = "BadRequest.FieldViolation",
197 package = "google.rpc",
198 file = "google/rpc/error_details.proto"
199 );
200
201 impl_known_type!(
202 target = Link,
203 name = "Help.Link",
204 package = "google.rpc",
205 file = "google/rpc/error_details.proto"
206 );
207}