icu_time/scaffold/
into_option.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5use crate::{
6    zone::{TimeZoneVariant, UtcOffset, ZoneNameTimestamp},
7    Hour, Minute, Nanosecond, Second, TimeZone,
8};
9use icu_calendar::{types::*, AnyCalendarKind};
10
11/// Converts Self to an `Option<T>`, either `Some(T)` if able or `None`
12pub trait IntoOption<T> {
13    /// Return `self` as an `Option<T>`
14    fn into_option(self) -> Option<T>;
15}
16
17impl<T> IntoOption<T> for Option<T> {
18    #[inline]
19    fn into_option(self) -> Option<T> {
20        self
21    }
22}
23
24impl<T> IntoOption<T> for () {
25    #[inline]
26    fn into_option(self) -> Option<T> {
27        None
28    }
29}
30
31impl IntoOption<YearInfo> for YearInfo {
32    #[inline]
33    fn into_option(self) -> Option<Self> {
34        Some(self)
35    }
36}
37
38impl IntoOption<MonthInfo> for MonthInfo {
39    #[inline]
40    fn into_option(self) -> Option<Self> {
41        Some(self)
42    }
43}
44
45impl IntoOption<DayOfMonth> for DayOfMonth {
46    #[inline]
47    fn into_option(self) -> Option<Self> {
48        Some(self)
49    }
50}
51
52impl IntoOption<Weekday> for Weekday {
53    #[inline]
54    fn into_option(self) -> Option<Self> {
55        Some(self)
56    }
57}
58
59impl IntoOption<DayOfYear> for DayOfYear {
60    #[inline]
61    fn into_option(self) -> Option<Self> {
62        Some(self)
63    }
64}
65
66impl IntoOption<AnyCalendarKind> for AnyCalendarKind {
67    #[inline]
68    fn into_option(self) -> Option<Self> {
69        Some(self)
70    }
71}
72
73impl IntoOption<Hour> for Hour {
74    #[inline]
75    fn into_option(self) -> Option<Self> {
76        Some(self)
77    }
78}
79
80impl IntoOption<Minute> for Minute {
81    #[inline]
82    fn into_option(self) -> Option<Self> {
83        Some(self)
84    }
85}
86
87impl IntoOption<Second> for Second {
88    #[inline]
89    fn into_option(self) -> Option<Self> {
90        Some(self)
91    }
92}
93
94impl IntoOption<Nanosecond> for Nanosecond {
95    #[inline]
96    fn into_option(self) -> Option<Self> {
97        Some(self)
98    }
99}
100
101impl IntoOption<TimeZone> for TimeZone {
102    #[inline]
103    fn into_option(self) -> Option<Self> {
104        Some(self)
105    }
106}
107
108impl IntoOption<UtcOffset> for UtcOffset {
109    #[inline]
110    fn into_option(self) -> Option<Self> {
111        Some(self)
112    }
113}
114
115impl IntoOption<TimeZoneVariant> for TimeZoneVariant {
116    #[inline]
117    fn into_option(self) -> Option<Self> {
118        Some(self)
119    }
120}
121
122impl IntoOption<ZoneNameTimestamp> for ZoneNameTimestamp {
123    #[inline]
124    fn into_option(self) -> Option<Self> {
125        Some(self)
126    }
127}