proto_types/common/
mod.rs1#![allow(clippy::doc_overindented_list_items)]
2#![allow(clippy::doc_lazy_continuation)]
3
4use std::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 pub fn new(extension: String, kind: phone_number::Kind) -> Self {
59 Self {
60 extension,
61 kind: Some(kind),
62 }
63 }
64
65 pub fn has_kind(&self) -> bool {
67 self.kind.is_some()
68 }
69}
70
71impl CalendarPeriod {
72 pub fn is_unspecified(&self) -> bool {
74 matches!(self, Self::Unspecified)
75 }
76
77 pub fn is_day(&self) -> bool {
79 matches!(self, CalendarPeriod::Day)
80 }
81
82 pub fn is_week(&self) -> bool {
84 matches!(self, CalendarPeriod::Week)
85 }
86
87 pub fn is_fortnight(&self) -> bool {
89 matches!(self, CalendarPeriod::Fortnight)
90 }
91
92 pub fn is_month(&self) -> bool {
94 matches!(self, CalendarPeriod::Month)
95 }
96
97 pub fn is_quarter(&self) -> bool {
99 matches!(self, CalendarPeriod::Quarter)
100 }
101
102 pub fn is_half(&self) -> bool {
104 matches!(self, CalendarPeriod::Half)
105 }
106
107 pub fn is_year(&self) -> bool {
109 matches!(self, CalendarPeriod::Year)
110 }
111}
112
113impl DayOfWeek {
114 pub fn is_unspecified(&self) -> bool {
116 matches!(self, Self::Unspecified)
117 }
118
119 pub fn is_monday(&self) -> bool {
121 matches!(self, Self::Monday)
122 }
123
124 pub fn is_tuesday(&self) -> bool {
126 matches!(self, Self::Tuesday)
127 }
128
129 pub fn is_wednesday(&self) -> bool {
131 matches!(self, Self::Wednesday)
132 }
133
134 pub fn is_thursday(&self) -> bool {
136 matches!(self, Self::Thursday)
137 }
138
139 pub fn is_friday(&self) -> bool {
141 matches!(self, Self::Friday)
142 }
143
144 pub fn is_saturday(&self) -> bool {
146 matches!(self, Self::Saturday)
147 }
148
149 pub fn is_sunday(&self) -> bool {
151 matches!(self, Self::Sunday)
152 }
153
154 pub fn as_title_case(&self) -> &str {
156 match self {
157 DayOfWeek::Unspecified => "Unspecified",
158 DayOfWeek::Monday => "Monday",
159 DayOfWeek::Tuesday => "Tuesday",
160 DayOfWeek::Wednesday => "Wednesday",
161 DayOfWeek::Thursday => "Thursday",
162 DayOfWeek::Friday => "Friday",
163 DayOfWeek::Saturday => "Saturday",
164 DayOfWeek::Sunday => "Sunday",
165 }
166 }
167}
168
169impl Month {
170 pub fn is_unspecified(&self) -> bool {
172 matches!(self, Self::Unspecified)
173 }
174
175 pub fn is_january(&self) -> bool {
177 matches!(self, Self::January)
178 }
179
180 pub fn is_february(&self) -> bool {
182 matches!(self, Self::February)
183 }
184
185 pub fn is_march(&self) -> bool {
187 matches!(self, Self::March)
188 }
189
190 pub fn is_april(&self) -> bool {
192 matches!(self, Self::April)
193 }
194
195 pub fn is_may(&self) -> bool {
197 matches!(self, Self::May)
198 }
199
200 pub fn is_june(&self) -> bool {
202 matches!(self, Self::June)
203 }
204
205 pub fn is_july(&self) -> bool {
207 matches!(self, Self::July)
208 }
209
210 pub fn is_august(&self) -> bool {
212 matches!(self, Self::August)
213 }
214
215 pub fn is_september(&self) -> bool {
217 matches!(self, Self::September)
218 }
219
220 pub fn is_october(&self) -> bool {
222 matches!(self, Self::October)
223 }
224
225 pub fn is_november(&self) -> bool {
227 matches!(self, Self::November)
228 }
229
230 pub fn is_december(&self) -> bool {
232 matches!(self, Self::December)
233 }
234
235 pub fn as_title_case(&self) -> &str {
237 match self {
238 Month::Unspecified => "Unspecified",
239 Month::January => "January",
240 Month::February => "February",
241 Month::March => "March",
242 Month::April => "April",
243 Month::May => "May",
244 Month::June => "June",
245 Month::July => "July",
246 Month::August => "August",
247 Month::September => "September",
248 Month::October => "October",
249 Month::November => "November",
250 Month::December => "December",
251 }
252 }
253}
254
255impl Display for DayOfWeek {
256 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
257 write!(f, "{}", self.as_title_case())
258 }
259}
260
261impl Display for Month {
262 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
263 write!(f, "{}", self.as_title_case())
264 }
265}