Skip to main content

proto_types/common/
mod.rs

1#![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/// Implementations for the google.type.LatLng message.
15#[cfg(feature = "latlng")]
16pub mod latlng;
17
18/// Implementations for the google.type.Color message.
19#[cfg(feature = "color")]
20pub mod color;
21
22/// Implementations for the google.type.Date message.
23#[cfg(feature = "date")]
24pub mod date;
25
26/// Implementations for the google.type.DateTime message.
27#[cfg(feature = "datetime")]
28pub mod datetime;
29
30/// Implementations for the google.type.Decimal message.
31#[cfg(feature = "decimal")]
32pub mod decimal;
33
34/// Implementations for the google.type.Fraction message.
35#[cfg(feature = "fraction")]
36pub mod fraction;
37
38/// Implementations for the google.type.Interval message.
39#[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/// Implementations for the google.type.TimeOfDay message.
52#[cfg(feature = "timeofday")]
53pub mod time_of_day;
54
55#[cfg(feature = "phone_number")]
56impl PhoneNumber {
57	/// Returns a new [`PhoneNumber`] instance. Ensures that `kind` is always set, as required by the spec.
58	#[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	/// Returns false if the field `kind` is missing, which means that the instance is invalid.
68	#[must_use]
69	#[inline]
70	pub const fn has_kind(&self) -> bool {
71		self.kind.is_some()
72	}
73}
74
75impl CalendarPeriod {
76	/// Checks if the value is of the `unspecified` variant.
77	#[must_use]
78	#[inline]
79	pub const fn is_unspecified(&self) -> bool {
80		matches!(self, Self::Unspecified)
81	}
82
83	/// Checks if the calendar period is a day.
84	#[must_use]
85	#[inline]
86	pub const fn is_day(&self) -> bool {
87		matches!(self, Self::Day)
88	}
89
90	/// Checks if the calendar period is a week.
91	#[must_use]
92	#[inline]
93	pub const fn is_week(&self) -> bool {
94		matches!(self, Self::Week)
95	}
96
97	/// Checks if the calendar period is a fortnight.
98	#[must_use]
99	#[inline]
100	pub const fn is_fortnight(&self) -> bool {
101		matches!(self, Self::Fortnight)
102	}
103
104	/// Checks if the calendar period is a month.
105	#[inline]
106	#[must_use]
107	pub const fn is_month(&self) -> bool {
108		matches!(self, Self::Month)
109	}
110
111	/// Checks if the calendar period is a quarter.
112	#[must_use]
113	#[inline]
114	pub const fn is_quarter(&self) -> bool {
115		matches!(self, Self::Quarter)
116	}
117
118	/// Checks if the calendar period is a half-year.
119	#[must_use]
120	#[inline]
121	pub const fn is_half(&self) -> bool {
122		matches!(self, Self::Half)
123	}
124
125	/// Checks if the calendar period is a year.
126	#[must_use]
127	#[inline]
128	pub const fn is_year(&self) -> bool {
129		matches!(self, Self::Year)
130	}
131}
132
133impl DayOfWeek {
134	/// Checks if the value is of the `unspecified` variant.
135	#[must_use]
136	#[inline]
137	pub const fn is_unspecified(&self) -> bool {
138		matches!(self, Self::Unspecified)
139	}
140
141	/// Returns true if the day of the variant is Monday.
142	#[must_use]
143	#[inline]
144	pub const fn is_monday(&self) -> bool {
145		matches!(self, Self::Monday)
146	}
147
148	/// Returns true if the day of the variant is Tuesday.
149	#[must_use]
150	#[inline]
151	pub const fn is_tuesday(&self) -> bool {
152		matches!(self, Self::Tuesday)
153	}
154
155	/// Returns true if the day of the variant is Wednesday.
156	#[must_use]
157	#[inline]
158	pub const fn is_wednesday(&self) -> bool {
159		matches!(self, Self::Wednesday)
160	}
161
162	/// Returns true if the day of the variant is Thursday.
163	#[must_use]
164	#[inline]
165	pub const fn is_thursday(&self) -> bool {
166		matches!(self, Self::Thursday)
167	}
168
169	/// Returns true if the day of the variant is Friday.
170	#[must_use]
171	#[inline]
172	pub const fn is_friday(&self) -> bool {
173		matches!(self, Self::Friday)
174	}
175
176	/// Returns true if the day of the variant is Saturday.
177	#[must_use]
178	#[inline]
179	pub const fn is_saturday(&self) -> bool {
180		matches!(self, Self::Saturday)
181	}
182
183	/// Returns true if the day of the variant is Sunday.
184	#[must_use]
185	#[inline]
186	pub const fn is_sunday(&self) -> bool {
187		matches!(self, Self::Sunday)
188	}
189
190	/// Returns the name of the day in title case.
191	#[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	/// Checks if the value is of the `Unspecified` variant.
209	#[must_use]
210	#[inline]
211	pub const fn is_unspecified(&self) -> bool {
212		matches!(self, Self::Unspecified)
213	}
214
215	/// Returns true if the month variant is January.
216	#[must_use]
217	#[inline]
218	pub const fn is_january(&self) -> bool {
219		matches!(self, Self::January)
220	}
221
222	/// Returns true if the month variant is February.
223	#[must_use]
224	#[inline]
225	pub const fn is_february(&self) -> bool {
226		matches!(self, Self::February)
227	}
228
229	/// Returns true if the month variant is March.
230	#[must_use]
231	#[inline]
232	pub const fn is_march(&self) -> bool {
233		matches!(self, Self::March)
234	}
235
236	/// Returns true if the month variant is April.
237	#[must_use]
238	#[inline]
239	pub const fn is_april(&self) -> bool {
240		matches!(self, Self::April)
241	}
242
243	/// Returns true if the month variant is May.
244	#[must_use]
245	#[inline]
246	pub const fn is_may(&self) -> bool {
247		matches!(self, Self::May)
248	}
249
250	/// Returns true if the month variant is June.
251	#[must_use]
252	#[inline]
253	pub const fn is_june(&self) -> bool {
254		matches!(self, Self::June)
255	}
256
257	/// Returns true if the month variant is July.
258	#[must_use]
259	#[inline]
260	pub const fn is_july(&self) -> bool {
261		matches!(self, Self::July)
262	}
263
264	/// Returns true if the month variant is August.
265	#[must_use]
266	#[inline]
267	pub const fn is_august(&self) -> bool {
268		matches!(self, Self::August)
269	}
270
271	/// Returns true if the month variant is September.
272	#[must_use]
273	#[inline]
274	pub const fn is_september(&self) -> bool {
275		matches!(self, Self::September)
276	}
277
278	/// Returns true if the month variant is October.
279	#[must_use]
280	#[inline]
281	pub const fn is_october(&self) -> bool {
282		matches!(self, Self::October)
283	}
284
285	/// Returns true if the month variant is November.
286	#[must_use]
287	#[inline]
288	pub const fn is_november(&self) -> bool {
289		matches!(self, Self::November)
290	}
291
292	/// Returns true if the month variant is December.
293	#[must_use]
294	#[inline]
295	pub const fn is_december(&self) -> bool {
296		matches!(self, Self::December)
297	}
298
299	/// Returns the name of the month in title case.
300	#[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}