proto_types/common/
mod.rs1#![allow(clippy::doc_overindented_list_items)]
2#![allow(clippy::doc_lazy_continuation)]
3
4use core::fmt::Display;
5
6include!("./google.type.rs");
7
8#[cfg(feature = "serde")]
9mod common_serde_impls;
10
11#[cfg(feature = "cel")]
12mod cel_common_types_impls;
13
14#[cfg(feature = "latlng")]
16pub mod latlng;
17
18#[cfg(feature = "color")]
20pub mod color;
21
22#[cfg(feature = "date")]
24pub mod date;
25
26#[cfg(feature = "datetime")]
28pub mod datetime;
29
30#[cfg(feature = "decimal")]
32pub mod decimal;
33
34#[cfg(feature = "fraction")]
36pub mod fraction;
37
38#[cfg(feature = "interval")]
40pub mod interval;
41
42#[cfg(feature = "localized_text")]
43mod localized_text;
44
45#[cfg(feature = "money")]
46pub mod money;
47
48#[cfg(feature = "postal_address")]
49mod postal_address;
50
51#[cfg(feature = "timeofday")]
53pub mod time_of_day;
54
55#[cfg(feature = "phone_number")]
56impl PhoneNumber {
57 #[must_use]
59 #[inline]
60 pub const fn new(extension: crate::String, kind: phone_number::Kind) -> Self {
61 Self {
62 extension,
63 kind: Some(kind),
64 }
65 }
66
67 #[must_use]
69 #[inline]
70 pub const fn has_kind(&self) -> bool {
71 self.kind.is_some()
72 }
73}
74
75impl CalendarPeriod {
76 #[must_use]
78 #[inline]
79 pub const fn is_unspecified(&self) -> bool {
80 matches!(self, Self::Unspecified)
81 }
82
83 #[must_use]
85 #[inline]
86 pub const fn is_day(&self) -> bool {
87 matches!(self, Self::Day)
88 }
89
90 #[must_use]
92 #[inline]
93 pub const fn is_week(&self) -> bool {
94 matches!(self, Self::Week)
95 }
96
97 #[must_use]
99 #[inline]
100 pub const fn is_fortnight(&self) -> bool {
101 matches!(self, Self::Fortnight)
102 }
103
104 #[inline]
106 #[must_use]
107 pub const fn is_month(&self) -> bool {
108 matches!(self, Self::Month)
109 }
110
111 #[must_use]
113 #[inline]
114 pub const fn is_quarter(&self) -> bool {
115 matches!(self, Self::Quarter)
116 }
117
118 #[must_use]
120 #[inline]
121 pub const fn is_half(&self) -> bool {
122 matches!(self, Self::Half)
123 }
124
125 #[must_use]
127 #[inline]
128 pub const fn is_year(&self) -> bool {
129 matches!(self, Self::Year)
130 }
131}
132
133impl DayOfWeek {
134 #[must_use]
136 #[inline]
137 pub const fn is_unspecified(&self) -> bool {
138 matches!(self, Self::Unspecified)
139 }
140
141 #[must_use]
143 #[inline]
144 pub const fn is_monday(&self) -> bool {
145 matches!(self, Self::Monday)
146 }
147
148 #[must_use]
150 #[inline]
151 pub const fn is_tuesday(&self) -> bool {
152 matches!(self, Self::Tuesday)
153 }
154
155 #[must_use]
157 #[inline]
158 pub const fn is_wednesday(&self) -> bool {
159 matches!(self, Self::Wednesday)
160 }
161
162 #[must_use]
164 #[inline]
165 pub const fn is_thursday(&self) -> bool {
166 matches!(self, Self::Thursday)
167 }
168
169 #[must_use]
171 #[inline]
172 pub const fn is_friday(&self) -> bool {
173 matches!(self, Self::Friday)
174 }
175
176 #[must_use]
178 #[inline]
179 pub const fn is_saturday(&self) -> bool {
180 matches!(self, Self::Saturday)
181 }
182
183 #[must_use]
185 #[inline]
186 pub const fn is_sunday(&self) -> bool {
187 matches!(self, Self::Sunday)
188 }
189
190 #[must_use]
192 #[inline]
193 pub const fn as_title_case(&self) -> &'static str {
194 match self {
195 Self::Unspecified => "Unspecified",
196 Self::Monday => "Monday",
197 Self::Tuesday => "Tuesday",
198 Self::Wednesday => "Wednesday",
199 Self::Thursday => "Thursday",
200 Self::Friday => "Friday",
201 Self::Saturday => "Saturday",
202 Self::Sunday => "Sunday",
203 }
204 }
205}
206
207impl Month {
208 #[must_use]
210 #[inline]
211 pub const fn is_unspecified(&self) -> bool {
212 matches!(self, Self::Unspecified)
213 }
214
215 #[must_use]
217 #[inline]
218 pub const fn is_january(&self) -> bool {
219 matches!(self, Self::January)
220 }
221
222 #[must_use]
224 #[inline]
225 pub const fn is_february(&self) -> bool {
226 matches!(self, Self::February)
227 }
228
229 #[must_use]
231 #[inline]
232 pub const fn is_march(&self) -> bool {
233 matches!(self, Self::March)
234 }
235
236 #[must_use]
238 #[inline]
239 pub const fn is_april(&self) -> bool {
240 matches!(self, Self::April)
241 }
242
243 #[must_use]
245 #[inline]
246 pub const fn is_may(&self) -> bool {
247 matches!(self, Self::May)
248 }
249
250 #[must_use]
252 #[inline]
253 pub const fn is_june(&self) -> bool {
254 matches!(self, Self::June)
255 }
256
257 #[must_use]
259 #[inline]
260 pub const fn is_july(&self) -> bool {
261 matches!(self, Self::July)
262 }
263
264 #[must_use]
266 #[inline]
267 pub const fn is_august(&self) -> bool {
268 matches!(self, Self::August)
269 }
270
271 #[must_use]
273 #[inline]
274 pub const fn is_september(&self) -> bool {
275 matches!(self, Self::September)
276 }
277
278 #[must_use]
280 #[inline]
281 pub const fn is_october(&self) -> bool {
282 matches!(self, Self::October)
283 }
284
285 #[must_use]
287 #[inline]
288 pub const fn is_november(&self) -> bool {
289 matches!(self, Self::November)
290 }
291
292 #[must_use]
294 #[inline]
295 pub const fn is_december(&self) -> bool {
296 matches!(self, Self::December)
297 }
298
299 #[must_use]
301 #[inline]
302 pub const fn as_title_case(&self) -> &'static str {
303 match self {
304 Self::Unspecified => "Unspecified",
305 Self::January => "January",
306 Self::February => "February",
307 Self::March => "March",
308 Self::April => "April",
309 Self::May => "May",
310 Self::June => "June",
311 Self::July => "July",
312 Self::August => "August",
313 Self::September => "September",
314 Self::October => "October",
315 Self::November => "November",
316 Self::December => "December",
317 }
318 }
319}
320
321impl Display for DayOfWeek {
322 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
323 write!(f, "{}", self.as_title_case())
324 }
325}
326
327impl Display for Month {
328 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
329 write!(f, "{}", self.as_title_case())
330 }
331}