proto_types/common/
mod.rs

1#![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/// 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  pub fn new(extension: String, kind: phone_number::Kind) -> Self {
59    Self {
60      extension,
61      kind: Some(kind),
62    }
63  }
64
65  /// Returns false if the field `kind` is missing, which means that the instance is invalid.
66  pub fn has_kind(&self) -> bool {
67    self.kind.is_some()
68  }
69}
70
71impl CalendarPeriod {
72  /// Checks if the value is of the `unspecified` variant.
73  pub fn is_unspecified(&self) -> bool {
74    matches!(self, Self::Unspecified)
75  }
76
77  /// Checks if the calendar period is a day.
78  pub fn is_day(&self) -> bool {
79    matches!(self, CalendarPeriod::Day)
80  }
81
82  /// Checks if the calendar period is a week.
83  pub fn is_week(&self) -> bool {
84    matches!(self, CalendarPeriod::Week)
85  }
86
87  /// Checks if the calendar period is a fortnight.
88  pub fn is_fortnight(&self) -> bool {
89    matches!(self, CalendarPeriod::Fortnight)
90  }
91
92  /// Checks if the calendar period is a month.
93  pub fn is_month(&self) -> bool {
94    matches!(self, CalendarPeriod::Month)
95  }
96
97  /// Checks if the calendar period is a quarter.
98  pub fn is_quarter(&self) -> bool {
99    matches!(self, CalendarPeriod::Quarter)
100  }
101
102  /// Checks if the calendar period is a half-year.
103  pub fn is_half(&self) -> bool {
104    matches!(self, CalendarPeriod::Half)
105  }
106
107  /// Checks if the calendar period is a year.
108  pub fn is_year(&self) -> bool {
109    matches!(self, CalendarPeriod::Year)
110  }
111}
112
113impl DayOfWeek {
114  /// Checks if the value is of the `unspecified` variant.
115  pub fn is_unspecified(&self) -> bool {
116    matches!(self, Self::Unspecified)
117  }
118
119  /// Returns true if the day of the variant is Monday.
120  pub fn is_monday(&self) -> bool {
121    matches!(self, Self::Monday)
122  }
123
124  /// Returns true if the day of the variant is Tuesday.
125  pub fn is_tuesday(&self) -> bool {
126    matches!(self, Self::Tuesday)
127  }
128
129  /// Returns true if the day of the variant is Wednesday.
130  pub fn is_wednesday(&self) -> bool {
131    matches!(self, Self::Wednesday)
132  }
133
134  /// Returns true if the day of the variant is Thursday.
135  pub fn is_thursday(&self) -> bool {
136    matches!(self, Self::Thursday)
137  }
138
139  /// Returns true if the day of the variant is Friday.
140  pub fn is_friday(&self) -> bool {
141    matches!(self, Self::Friday)
142  }
143
144  /// Returns true if the day of the variant is Saturday.
145  pub fn is_saturday(&self) -> bool {
146    matches!(self, Self::Saturday)
147  }
148
149  /// Returns true if the day of the variant is Sunday.
150  pub fn is_sunday(&self) -> bool {
151    matches!(self, Self::Sunday)
152  }
153
154  /// Returns the name of the day in title case.
155  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  /// Checks if the value is of the `Unspecified` variant.
171  pub fn is_unspecified(&self) -> bool {
172    matches!(self, Self::Unspecified)
173  }
174
175  /// Returns true if the month variant is January.
176  pub fn is_january(&self) -> bool {
177    matches!(self, Self::January)
178  }
179
180  /// Returns true if the month variant is February.
181  pub fn is_february(&self) -> bool {
182    matches!(self, Self::February)
183  }
184
185  /// Returns true if the month variant is March.
186  pub fn is_march(&self) -> bool {
187    matches!(self, Self::March)
188  }
189
190  /// Returns true if the month variant is April.
191  pub fn is_april(&self) -> bool {
192    matches!(self, Self::April)
193  }
194
195  /// Returns true if the month variant is May.
196  pub fn is_may(&self) -> bool {
197    matches!(self, Self::May)
198  }
199
200  /// Returns true if the month variant is June.
201  pub fn is_june(&self) -> bool {
202    matches!(self, Self::June)
203  }
204
205  /// Returns true if the month variant is July.
206  pub fn is_july(&self) -> bool {
207    matches!(self, Self::July)
208  }
209
210  /// Returns true if the month variant is August.
211  pub fn is_august(&self) -> bool {
212    matches!(self, Self::August)
213  }
214
215  /// Returns true if the month variant is September.
216  pub fn is_september(&self) -> bool {
217    matches!(self, Self::September)
218  }
219
220  /// Returns true if the month variant is October.
221  pub fn is_october(&self) -> bool {
222    matches!(self, Self::October)
223  }
224
225  /// Returns true if the month variant is November.
226  pub fn is_november(&self) -> bool {
227    matches!(self, Self::November)
228  }
229
230  /// Returns true if the month variant is December.
231  pub fn is_december(&self) -> bool {
232    matches!(self, Self::December)
233  }
234
235  /// Returns the name of the month in title case.
236  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}