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