/rust/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-0.2.20/src/util/b.rs
Line | Count | Source |
1 | | /*! |
2 | | A module for constants and various base utilities. |
3 | | |
4 | | This module is a work-in-progress that may lead to helping us move off of |
5 | | ranged integers. I'm not quite sure where this will go. |
6 | | */ |
7 | | |
8 | | #![allow(dead_code)] |
9 | | |
10 | | use crate::{Error, SignedDuration}; |
11 | | |
12 | | pub(crate) const DAYS_PER_WEEK: i64 = 7; |
13 | | pub(crate) const HOURS_PER_CIVIL_DAY: i64 = 24; |
14 | | pub(crate) const MINS_PER_CIVIL_DAY: i64 = HOURS_PER_CIVIL_DAY * MINS_PER_HOUR; |
15 | | pub(crate) const MINS_PER_HOUR: i64 = 60; |
16 | | pub(crate) const SECS_PER_WEEK: i64 = DAYS_PER_WEEK * SECS_PER_CIVIL_DAY; |
17 | | pub(crate) const SECS_PER_CIVIL_DAY: i64 = HOURS_PER_CIVIL_DAY * SECS_PER_HOUR; |
18 | | pub(crate) const SECS_PER_HOUR: i64 = SECS_PER_MIN * MINS_PER_HOUR; |
19 | | pub(crate) const SECS_PER_MIN: i64 = 60; |
20 | | pub(crate) const MILLIS_PER_CIVIL_DAY: i64 = |
21 | | SECS_PER_CIVIL_DAY * MILLIS_PER_SEC; |
22 | | pub(crate) const MILLIS_PER_SEC: i64 = 1_000; |
23 | | pub(crate) const MICROS_PER_CIVIL_DAY: i64 = |
24 | | SECS_PER_CIVIL_DAY * MICROS_PER_SEC; |
25 | | pub(crate) const MICROS_PER_SEC: i64 = MILLIS_PER_SEC * MICROS_PER_MILLI; |
26 | | pub(crate) const MICROS_PER_MILLI: i64 = 1_000; |
27 | | pub(crate) const NANOS_PER_WEEK: i64 = DAYS_PER_WEEK * NANOS_PER_CIVIL_DAY; |
28 | | pub(crate) const NANOS_PER_CIVIL_DAY: i64 = |
29 | | HOURS_PER_CIVIL_DAY * NANOS_PER_HOUR; |
30 | | pub(crate) const NANOS_PER_HOUR: i64 = MINS_PER_HOUR * NANOS_PER_MIN; |
31 | | pub(crate) const NANOS_PER_MIN: i64 = SECS_PER_MIN * NANOS_PER_SEC; |
32 | | pub(crate) const NANOS_PER_SEC: i64 = MILLIS_PER_SEC * NANOS_PER_MILLI; |
33 | | pub(crate) const NANOS_PER_MILLI: i64 = MICROS_PER_MILLI * NANOS_PER_MICRO; |
34 | | pub(crate) const NANOS_PER_MICRO: i64 = 1_000; |
35 | | |
36 | | pub(crate) const DAYS_PER_WEEK_32: i32 = 7; |
37 | | pub(crate) const HOURS_PER_CIVIL_DAY_32: i32 = 24; |
38 | | pub(crate) const MINS_PER_HOUR_32: i32 = 60; |
39 | | pub(crate) const SECS_PER_CIVIL_DAY_32: i32 = |
40 | | HOURS_PER_CIVIL_DAY_32 * SECS_PER_HOUR_32; |
41 | | pub(crate) const SECS_PER_HOUR_32: i32 = SECS_PER_MIN_32 * MINS_PER_HOUR_32; |
42 | | pub(crate) const SECS_PER_MIN_32: i32 = 60; |
43 | | pub(crate) const MILLIS_PER_SEC_32: i32 = 1_000; |
44 | | pub(crate) const MICROS_PER_SEC_32: i32 = |
45 | | MILLIS_PER_SEC_32 * MICROS_PER_MILLI_32; |
46 | | pub(crate) const MICROS_PER_MILLI_32: i32 = 1_000; |
47 | | pub(crate) const NANOS_PER_SEC_32: i32 = |
48 | | MILLIS_PER_SEC_32 * NANOS_PER_MILLI_32; |
49 | | pub(crate) const NANOS_PER_MILLI_32: i32 = |
50 | | MICROS_PER_MILLI_32 * NANOS_PER_MICRO_32; |
51 | | pub(crate) const NANOS_PER_MICRO_32: i32 = 1_000; |
52 | | |
53 | | /// This macro writes out the boiler plate to define a boundary type. |
54 | | /// |
55 | | /// Specifically, it implements the `Bounds` trait and provides a few |
56 | | /// concrete methods. The concrete methods are mostly wrappers around |
57 | | /// the generic trait methods. They are provided so that callers don't |
58 | | /// have to import the `Bounds` trait to use them. |
59 | | macro_rules! define_bounds { |
60 | | ($(( |
61 | | // The name of the boundary type. |
62 | | $name:ident, |
63 | | // The underlying primitive type. This is usually, but not always, |
64 | | // the smallest signed primitive integer type that can represent both |
65 | | // the minimum and maximum boundary values. |
66 | | $ty:ident, |
67 | | // A short human readable description that appears in error messages |
68 | | // when the boundaries of this type are violated. |
69 | | $what:expr, |
70 | | // The minimum value. |
71 | | $min:expr, |
72 | | // The maximum value. |
73 | | $max:expr $(,)? |
74 | | )),* $(,)?) => { |
75 | | $( |
76 | | pub(crate) struct $name(()); |
77 | | |
78 | | impl Bounds for $name { |
79 | | const WHAT: &'static str = $what; |
80 | | const MIN: Self::Primitive = $min; |
81 | | const MAX: Self::Primitive = $max; |
82 | | type Primitive = $ty; |
83 | | |
84 | | #[cold] |
85 | | #[inline(never)] |
86 | 0 | fn error() -> BoundsError { |
87 | 0 | BoundsError::$name(RawBoundsError::new()) |
88 | 0 | } Unexecuted instantiation: <jiff::util::b::NthWeekday as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::OffsetHours as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::OffsetMinutes as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::OffsetSeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SubsecNanosecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::UnixMilliseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::UnixMicroseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::UnixSeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::WeekNum as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::YearCE as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Second as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanYears as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanMonths as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanWeeks as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanDays as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanHours as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanMinutes as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanSeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanMilliseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanMicroseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanMultiple as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::SpanNanoseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::YearBCE as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::YearTwoDigit as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::DayOfYear as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Hour as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Hour12 as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::ISOWeek as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::ISOYear as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Increment as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Increment32 as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::LeapSecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Microsecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Millisecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Minute as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Month as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Nanosecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Century as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::CivilDaySecond as jiff::util::b::Bounds>::error Unexecuted instantiation: <jiff::util::b::Day as jiff::util::b::Bounds>::error |
89 | | } |
90 | | |
91 | | impl $name { |
92 | | pub(crate) const MIN: $ty = <$name as Bounds>::MIN; |
93 | | pub(crate) const MAX: $ty = <$name as Bounds>::MAX; |
94 | | const LEN: i128 = Self::MAX as i128 - Self::MIN as i128 + 1; |
95 | | |
96 | | #[cold] |
97 | 0 | pub(crate) const fn error() -> BoundsError { |
98 | 0 | BoundsError::$name(RawBoundsError::new()) |
99 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixSeconds>::error Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::error Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::error Unexecuted instantiation: <jiff::util::b::Day>::error Unexecuted instantiation: <jiff::util::b::NthWeekday>::error Unexecuted instantiation: <jiff::util::b::OffsetHours>::error Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::error Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::error Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::error Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::error Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::error Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::error Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::error Unexecuted instantiation: <jiff::util::b::WeekNum>::error Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::error Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::error Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::error Unexecuted instantiation: <jiff::util::b::Year>::error Unexecuted instantiation: <jiff::util::b::YearCE>::error Unexecuted instantiation: <jiff::util::b::Second>::error Unexecuted instantiation: <jiff::util::b::SpanMultiple>::error Unexecuted instantiation: <jiff::util::b::YearBCE>::error Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::error Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::error Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::error Unexecuted instantiation: <jiff::util::b::DayOfYear>::error Unexecuted instantiation: <jiff::util::b::Hour>::error Unexecuted instantiation: <jiff::util::b::Hour12>::error Unexecuted instantiation: <jiff::util::b::ISOYear>::error Unexecuted instantiation: <jiff::util::b::Increment>::error Unexecuted instantiation: <jiff::util::b::Increment32>::error Unexecuted instantiation: <jiff::util::b::LeapSecond>::error Unexecuted instantiation: <jiff::util::b::Microsecond>::error Unexecuted instantiation: <jiff::util::b::Millisecond>::error Unexecuted instantiation: <jiff::util::b::Minute>::error Unexecuted instantiation: <jiff::util::b::Month>::error Unexecuted instantiation: <jiff::util::b::Nanosecond>::error Unexecuted instantiation: <jiff::util::b::Century>::error Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::error Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::error Unexecuted instantiation: <jiff::util::b::SpanYears>::error Unexecuted instantiation: <jiff::util::b::SpanMonths>::error Unexecuted instantiation: <jiff::util::b::SpanWeeks>::error Unexecuted instantiation: <jiff::util::b::SpanDays>::error Unexecuted instantiation: <jiff::util::b::SpanHours>::error Unexecuted instantiation: <jiff::util::b::SpanMinutes>::error Unexecuted instantiation: <jiff::util::b::SpanSeconds>::error Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::error Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::error Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::error Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::error Unexecuted instantiation: <jiff::util::b::ISOWeek>::error |
100 | | |
101 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
102 | 0 | pub(crate) fn check(n: impl Into<i64>) -> Result<$ty, BoundsError> { |
103 | 0 | <$name as Bounds>::check(n) |
104 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixSeconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::YearCE>::check::<i16> Unexecuted instantiation: <jiff::util::b::YearBCE>::check::<i16> Unexecuted instantiation: <jiff::util::b::Day>::check::<i8> Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::check::<i32> Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanDays>::check::<i64> Unexecuted instantiation: <jiff::util::b::Increment32>::check::<i64> Unexecuted instantiation: <jiff::util::b::NthWeekday>::check::<_> Unexecuted instantiation: <jiff::util::b::OffsetHours>::check::<_> Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::check::<_> Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::check::<_> Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::check::<_> Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::check::<_> Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::check::<_> Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::check::<_> Unexecuted instantiation: <jiff::util::b::SpanMultiple>::check::<_> Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::check::<_> Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::check::<_> Unexecuted instantiation: <jiff::util::b::Increment>::check::<_> Unexecuted instantiation: <jiff::util::b::LeapSecond>::check::<_> Unexecuted instantiation: <jiff::util::b::Microsecond>::check::<_> Unexecuted instantiation: <jiff::util::b::Millisecond>::check::<_> Unexecuted instantiation: <jiff::util::b::Nanosecond>::check::<_> Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::check::<_> Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::check::<_> Unexecuted instantiation: <jiff::util::b::Year>::check::<i16> Unexecuted instantiation: <jiff::util::b::Month>::check::<i8> Unexecuted instantiation: <jiff::util::b::SpanYears>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMonths>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanWeeks>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanHours>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMinutes>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanSeconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::ISOWeek>::check::<i8> Unexecuted instantiation: <jiff::util::b::ISOYear>::check::<i16> Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::check::<i32> Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::check::<i32> Unexecuted instantiation: <jiff::util::b::UnixSeconds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Second>::check::<i8> Unexecuted instantiation: <jiff::util::b::Hour>::check::<i8> Unexecuted instantiation: <jiff::util::b::Minute>::check::<i8> Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::check::<u32> Unexecuted instantiation: <jiff::util::b::WeekNum>::check::<i64> Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::check::<i8> Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::check::<i8> Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::check::<i8> Unexecuted instantiation: <jiff::util::b::Year>::check::<i64> Unexecuted instantiation: <jiff::util::b::Second>::check::<i64> Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::check::<i64> Unexecuted instantiation: <jiff::util::b::DayOfYear>::check::<i64> Unexecuted instantiation: <jiff::util::b::Hour>::check::<i64> Unexecuted instantiation: <jiff::util::b::Hour12>::check::<i64> Unexecuted instantiation: <jiff::util::b::ISOWeek>::check::<i64> Unexecuted instantiation: <jiff::util::b::ISOYear>::check::<i64> Unexecuted instantiation: <jiff::util::b::Minute>::check::<i64> Unexecuted instantiation: <jiff::util::b::Month>::check::<i64> Unexecuted instantiation: <jiff::util::b::Century>::check::<i64> Unexecuted instantiation: <jiff::util::b::Day>::check::<i64> |
105 | | |
106 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
107 | 0 | pub(crate) const fn checkc(n: i64) -> Result<$ty, BoundsError> { |
108 | 0 | match self::checkc::$ty(n) { |
109 | 0 | Ok(n) => Ok(n), |
110 | 0 | Err(err) => Err(BoundsError::$name(err)), |
111 | | } |
112 | 0 | } Unexecuted instantiation: <jiff::util::b::OffsetHours>::checkc Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::checkc Unexecuted instantiation: <jiff::util::b::NthWeekday>::checkc Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::checkc Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::checkc Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checkc Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::checkc Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::checkc Unexecuted instantiation: <jiff::util::b::WeekNum>::checkc Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::checkc Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::checkc Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::checkc Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::checkc Unexecuted instantiation: <jiff::util::b::Year>::checkc Unexecuted instantiation: <jiff::util::b::YearCE>::checkc Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::checkc Unexecuted instantiation: <jiff::util::b::SpanYears>::checkc Unexecuted instantiation: <jiff::util::b::SpanMonths>::checkc Unexecuted instantiation: <jiff::util::b::SpanWeeks>::checkc Unexecuted instantiation: <jiff::util::b::SpanDays>::checkc Unexecuted instantiation: <jiff::util::b::SpanHours>::checkc Unexecuted instantiation: <jiff::util::b::SpanMinutes>::checkc Unexecuted instantiation: <jiff::util::b::SpanSeconds>::checkc Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::checkc Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::checkc Unexecuted instantiation: <jiff::util::b::SpanMultiple>::checkc Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::checkc Unexecuted instantiation: <jiff::util::b::YearBCE>::checkc Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::checkc Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::checkc Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::checkc Unexecuted instantiation: <jiff::util::b::DayOfYear>::checkc Unexecuted instantiation: <jiff::util::b::Hour12>::checkc Unexecuted instantiation: <jiff::util::b::ISOWeek>::checkc Unexecuted instantiation: <jiff::util::b::ISOYear>::checkc Unexecuted instantiation: <jiff::util::b::Increment>::checkc Unexecuted instantiation: <jiff::util::b::Increment32>::checkc Unexecuted instantiation: <jiff::util::b::LeapSecond>::checkc Unexecuted instantiation: <jiff::util::b::Microsecond>::checkc Unexecuted instantiation: <jiff::util::b::Millisecond>::checkc Unexecuted instantiation: <jiff::util::b::Month>::checkc Unexecuted instantiation: <jiff::util::b::Nanosecond>::checkc Unexecuted instantiation: <jiff::util::b::Century>::checkc Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checkc Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checkc Unexecuted instantiation: <jiff::util::b::Day>::checkc Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checkc Unexecuted instantiation: <jiff::util::b::Second>::checkc Unexecuted instantiation: <jiff::util::b::Hour>::checkc Unexecuted instantiation: <jiff::util::b::Minute>::checkc Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checkc Unexecuted instantiation: <jiff::util::b::UnixSeconds>::checkc |
113 | | |
114 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
115 | 0 | pub(crate) fn check128(n: impl Into<i128>) -> Result<$ty, BoundsError> { |
116 | 0 | <$name as Bounds>::check128(n) |
117 | 0 | } Unexecuted instantiation: <jiff::util::b::SpanDays>::check128::<i128> Unexecuted instantiation: <jiff::util::b::NthWeekday>::check128::<_> Unexecuted instantiation: <jiff::util::b::OffsetHours>::check128::<_> Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::check128::<_> Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check128::<_> Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::UnixSeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::WeekNum>::check128::<_> Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::check128::<_> Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::check128::<_> Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::check128::<_> Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::check128::<_> Unexecuted instantiation: <jiff::util::b::Year>::check128::<_> Unexecuted instantiation: <jiff::util::b::YearCE>::check128::<_> Unexecuted instantiation: <jiff::util::b::Second>::check128::<_> Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanYears>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanMonths>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanWeeks>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanHours>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanMinutes>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanSeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanMultiple>::check128::<_> Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::YearBCE>::check128::<_> Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::check128::<_> Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::check128::<_> Unexecuted instantiation: <jiff::util::b::DayOfYear>::check128::<_> Unexecuted instantiation: <jiff::util::b::Hour>::check128::<_> Unexecuted instantiation: <jiff::util::b::Hour12>::check128::<_> Unexecuted instantiation: <jiff::util::b::ISOWeek>::check128::<_> Unexecuted instantiation: <jiff::util::b::ISOYear>::check128::<_> Unexecuted instantiation: <jiff::util::b::Increment>::check128::<_> Unexecuted instantiation: <jiff::util::b::Increment32>::check128::<_> Unexecuted instantiation: <jiff::util::b::LeapSecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::Microsecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::Millisecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::Minute>::check128::<_> Unexecuted instantiation: <jiff::util::b::Month>::check128::<_> Unexecuted instantiation: <jiff::util::b::Nanosecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::Century>::check128::<_> Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::check128::<_> Unexecuted instantiation: <jiff::util::b::Day>::check128::<_> |
118 | | |
119 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
120 | 0 | pub(crate) fn parse(bytes: &[u8]) -> Result<$ty, Error> { |
121 | 0 | <$name as Bounds>::parse(bytes) |
122 | 0 | } Unexecuted instantiation: <jiff::util::b::OffsetHours>::parse Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::parse Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::parse Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::parse Unexecuted instantiation: <jiff::util::b::Year>::parse Unexecuted instantiation: <jiff::util::b::Hour>::parse Unexecuted instantiation: <jiff::util::b::ISOWeek>::parse Unexecuted instantiation: <jiff::util::b::LeapSecond>::parse Unexecuted instantiation: <jiff::util::b::Minute>::parse Unexecuted instantiation: <jiff::util::b::Month>::parse Unexecuted instantiation: <jiff::util::b::Day>::parse Unexecuted instantiation: <jiff::util::b::NthWeekday>::parse Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::parse Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::parse Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::parse Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::parse Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::parse Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::parse Unexecuted instantiation: <jiff::util::b::UnixSeconds>::parse Unexecuted instantiation: <jiff::util::b::WeekNum>::parse Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::parse Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::parse Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::parse Unexecuted instantiation: <jiff::util::b::YearCE>::parse Unexecuted instantiation: <jiff::util::b::Second>::parse Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::parse Unexecuted instantiation: <jiff::util::b::SpanYears>::parse Unexecuted instantiation: <jiff::util::b::SpanMonths>::parse Unexecuted instantiation: <jiff::util::b::SpanWeeks>::parse Unexecuted instantiation: <jiff::util::b::SpanDays>::parse Unexecuted instantiation: <jiff::util::b::SpanHours>::parse Unexecuted instantiation: <jiff::util::b::SpanMinutes>::parse Unexecuted instantiation: <jiff::util::b::SpanSeconds>::parse Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::parse Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::parse Unexecuted instantiation: <jiff::util::b::SpanMultiple>::parse Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::parse Unexecuted instantiation: <jiff::util::b::YearBCE>::parse Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::parse Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::parse Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::parse Unexecuted instantiation: <jiff::util::b::DayOfYear>::parse Unexecuted instantiation: <jiff::util::b::Hour12>::parse Unexecuted instantiation: <jiff::util::b::ISOYear>::parse Unexecuted instantiation: <jiff::util::b::Increment>::parse Unexecuted instantiation: <jiff::util::b::Increment32>::parse Unexecuted instantiation: <jiff::util::b::Microsecond>::parse Unexecuted instantiation: <jiff::util::b::Millisecond>::parse Unexecuted instantiation: <jiff::util::b::Nanosecond>::parse Unexecuted instantiation: <jiff::util::b::Century>::parse Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::parse Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::parse |
123 | | |
124 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
125 | 0 | pub(crate) fn checked_add(n1: $ty, n2: $ty) -> Result<$ty, BoundsError> { |
126 | 0 | <$name as Bounds>::checked_add(n1, n2) |
127 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checked_add Unexecuted instantiation: <jiff::util::b::UnixSeconds>::checked_add Unexecuted instantiation: <jiff::util::b::Year>::checked_add Unexecuted instantiation: <jiff::util::b::SpanMonths>::checked_add Unexecuted instantiation: <jiff::util::b::NthWeekday>::checked_add Unexecuted instantiation: <jiff::util::b::OffsetHours>::checked_add Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::checked_add Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::checked_add Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::checked_add Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checked_add Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checked_add Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::checked_add Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::checked_add Unexecuted instantiation: <jiff::util::b::WeekNum>::checked_add Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::checked_add Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::checked_add Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::checked_add Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::checked_add Unexecuted instantiation: <jiff::util::b::YearCE>::checked_add Unexecuted instantiation: <jiff::util::b::Second>::checked_add Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::checked_add Unexecuted instantiation: <jiff::util::b::SpanYears>::checked_add Unexecuted instantiation: <jiff::util::b::SpanWeeks>::checked_add Unexecuted instantiation: <jiff::util::b::SpanDays>::checked_add Unexecuted instantiation: <jiff::util::b::SpanHours>::checked_add Unexecuted instantiation: <jiff::util::b::SpanMinutes>::checked_add Unexecuted instantiation: <jiff::util::b::SpanSeconds>::checked_add Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::checked_add Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::checked_add Unexecuted instantiation: <jiff::util::b::SpanMultiple>::checked_add Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::checked_add Unexecuted instantiation: <jiff::util::b::YearBCE>::checked_add Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::checked_add Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::checked_add Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::checked_add Unexecuted instantiation: <jiff::util::b::DayOfYear>::checked_add Unexecuted instantiation: <jiff::util::b::Hour>::checked_add Unexecuted instantiation: <jiff::util::b::Hour12>::checked_add Unexecuted instantiation: <jiff::util::b::ISOWeek>::checked_add Unexecuted instantiation: <jiff::util::b::ISOYear>::checked_add Unexecuted instantiation: <jiff::util::b::Increment>::checked_add Unexecuted instantiation: <jiff::util::b::Increment32>::checked_add Unexecuted instantiation: <jiff::util::b::LeapSecond>::checked_add Unexecuted instantiation: <jiff::util::b::Microsecond>::checked_add Unexecuted instantiation: <jiff::util::b::Millisecond>::checked_add Unexecuted instantiation: <jiff::util::b::Minute>::checked_add Unexecuted instantiation: <jiff::util::b::Month>::checked_add Unexecuted instantiation: <jiff::util::b::Nanosecond>::checked_add Unexecuted instantiation: <jiff::util::b::Century>::checked_add Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checked_add Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checked_add Unexecuted instantiation: <jiff::util::b::Day>::checked_add |
128 | | |
129 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
130 | 0 | pub(crate) fn checked_sub(n1: $ty, n2: $ty) -> Result<$ty, BoundsError> { |
131 | 0 | <$name as Bounds>::checked_sub(n1, n2) |
132 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checked_sub Unexecuted instantiation: <jiff::util::b::Year>::checked_sub Unexecuted instantiation: <jiff::util::b::NthWeekday>::checked_sub Unexecuted instantiation: <jiff::util::b::OffsetHours>::checked_sub Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::checked_sub Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checked_sub Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checked_sub Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::UnixSeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::WeekNum>::checked_sub Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::checked_sub Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::checked_sub Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::checked_sub Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::checked_sub Unexecuted instantiation: <jiff::util::b::YearCE>::checked_sub Unexecuted instantiation: <jiff::util::b::Second>::checked_sub Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanYears>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanMonths>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanWeeks>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanDays>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanHours>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanMinutes>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanSeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanMultiple>::checked_sub Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::YearBCE>::checked_sub Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::checked_sub Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::checked_sub Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::checked_sub Unexecuted instantiation: <jiff::util::b::DayOfYear>::checked_sub Unexecuted instantiation: <jiff::util::b::Hour>::checked_sub Unexecuted instantiation: <jiff::util::b::Hour12>::checked_sub Unexecuted instantiation: <jiff::util::b::ISOWeek>::checked_sub Unexecuted instantiation: <jiff::util::b::ISOYear>::checked_sub Unexecuted instantiation: <jiff::util::b::Increment>::checked_sub Unexecuted instantiation: <jiff::util::b::Increment32>::checked_sub Unexecuted instantiation: <jiff::util::b::LeapSecond>::checked_sub Unexecuted instantiation: <jiff::util::b::Microsecond>::checked_sub Unexecuted instantiation: <jiff::util::b::Millisecond>::checked_sub Unexecuted instantiation: <jiff::util::b::Minute>::checked_sub Unexecuted instantiation: <jiff::util::b::Month>::checked_sub Unexecuted instantiation: <jiff::util::b::Nanosecond>::checked_sub Unexecuted instantiation: <jiff::util::b::Century>::checked_sub Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checked_sub Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checked_sub Unexecuted instantiation: <jiff::util::b::Day>::checked_sub |
133 | | |
134 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
135 | 0 | pub(crate) fn checked_mul(n1: $ty, n2: $ty) -> Result<$ty, BoundsError> { |
136 | 0 | <$name as Bounds>::checked_mul(n1, n2) |
137 | 0 | } Unexecuted instantiation: <jiff::util::b::SpanYears>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMonths>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanWeeks>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanDays>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanHours>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMinutes>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanSeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::NthWeekday>::checked_mul Unexecuted instantiation: <jiff::util::b::OffsetHours>::checked_mul Unexecuted instantiation: <jiff::util::b::OffsetMinutes>::checked_mul Unexecuted instantiation: <jiff::util::b::OffsetSeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checked_mul Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checked_mul Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checked_mul Unexecuted instantiation: <jiff::util::b::UnixMilliseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::UnixMicroseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::UnixSeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::WeekNum>::checked_mul Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::checked_mul Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::checked_mul Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::checked_mul Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::checked_mul Unexecuted instantiation: <jiff::util::b::Year>::checked_mul Unexecuted instantiation: <jiff::util::b::YearCE>::checked_mul Unexecuted instantiation: <jiff::util::b::Second>::checked_mul Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMultiple>::checked_mul Unexecuted instantiation: <jiff::util::b::YearBCE>::checked_mul Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::checked_mul Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds>::checked_mul Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds>::checked_mul Unexecuted instantiation: <jiff::util::b::DayOfYear>::checked_mul Unexecuted instantiation: <jiff::util::b::Hour>::checked_mul Unexecuted instantiation: <jiff::util::b::Hour12>::checked_mul Unexecuted instantiation: <jiff::util::b::ISOWeek>::checked_mul Unexecuted instantiation: <jiff::util::b::ISOYear>::checked_mul Unexecuted instantiation: <jiff::util::b::Increment>::checked_mul Unexecuted instantiation: <jiff::util::b::Increment32>::checked_mul Unexecuted instantiation: <jiff::util::b::LeapSecond>::checked_mul Unexecuted instantiation: <jiff::util::b::Microsecond>::checked_mul Unexecuted instantiation: <jiff::util::b::Millisecond>::checked_mul Unexecuted instantiation: <jiff::util::b::Minute>::checked_mul Unexecuted instantiation: <jiff::util::b::Month>::checked_mul Unexecuted instantiation: <jiff::util::b::Nanosecond>::checked_mul Unexecuted instantiation: <jiff::util::b::Century>::checked_mul Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checked_mul Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checked_mul Unexecuted instantiation: <jiff::util::b::Day>::checked_mul |
138 | | |
139 | | #[cfg(test)] |
140 | | pub(crate) fn arbitrary(g: &mut quickcheck::Gen) -> $ty { |
141 | | use quickcheck::Arbitrary; |
142 | | |
143 | | let mut n: $ty = <$ty>::arbitrary(g); |
144 | | n = n.wrapping_rem_euclid(Self::LEN as $ty); |
145 | | n += Self::MIN; |
146 | | n |
147 | | } |
148 | | } |
149 | | )* |
150 | | |
151 | | /// An error that indicates a value is out of its intended range. |
152 | | #[derive(Clone, Debug)] |
153 | | pub(crate) enum BoundsError { |
154 | | $($name(RawBoundsError<$name>),)* |
155 | | } |
156 | | |
157 | | impl core::fmt::Display for BoundsError { |
158 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
159 | 0 | match *self { |
160 | 0 | $(BoundsError::$name(ref err) => err.fmt(f),)* |
161 | | } |
162 | 0 | } |
163 | | } |
164 | | } |
165 | | } |
166 | | |
167 | | define_bounds! { |
168 | | (Century, i8, "century", 0, 99), |
169 | | ( |
170 | | CivilDayNanosecond, |
171 | | i64, |
172 | | "nanoseconds (in one civil day)", |
173 | | 0, |
174 | | NANOS_PER_CIVIL_DAY - 1, |
175 | | ), |
176 | | ( |
177 | | CivilDaySecond, |
178 | | i32, |
179 | | "seconds (in one civil day)", |
180 | | 0, |
181 | | SECS_PER_CIVIL_DAY_32 - 1, |
182 | | ), |
183 | | (Day, i8, "day", 1, 31), |
184 | | (DayOfYear, i16, "day-of-year", 1, 366), |
185 | | (Hour, i8, "hour", 0, 23), |
186 | | (Hour12, i8, "hour (12 hour clock)", 1, 12), |
187 | | (ISOWeek, i8, "iso-week", 1, 53), |
188 | | (ISOYear, i16, "iso-year", -9999, 9999), |
189 | | // This matches Temporal's range. |
190 | | // See: https://github.com/tc39/proposal-temporal/issues/2458#issuecomment-1380742911 |
191 | | (Increment, i64, "rounding increment", 1, 1_000_000_000), |
192 | | (Increment32, i32, "rounding increment", 1, 1_000_000_000), |
193 | | // This is only used in parsing. A value of `60` gets clamped to `59`. |
194 | | (LeapSecond, i8, "second", 0, 60), |
195 | | (Microsecond, i16, "microsecond", 0, 999), |
196 | | (Millisecond, i16, "millisecond", 0, 999), |
197 | | (Minute, i8, "minute", 0, 59), |
198 | | (Month, i8, "month", 1, 12), |
199 | | (Nanosecond, i16, "nanosecond", 0, 999), |
200 | | (NthWeekday, i32, "nth weekday", SpanWeeks::MIN, SpanWeeks::MAX), |
201 | | // The number of hours allowed in a time zone offset. |
202 | | // |
203 | | // This number was somewhat arbitrarily chosen. In part because it's bigger |
204 | | // than any current offset in actual use by a wide margin, and in part |
205 | | // because POSIX `TZ` strings require the ability to store offsets in the |
206 | | // range `-24:59:59..=25:59:59`. Note though that we make the range a |
207 | | // little bigger with `-25:59:59..=25:59:59` so that negating an offset |
208 | | // always produces a valid offset. |
209 | | // |
210 | | // Note that RFC 8536 actually allows offsets to be much bigger, namely, |
211 | | // in the range `(-2^31, 2^31)`, where both ends are _exclusive_ (`-2^31` |
212 | | // is explicitly disallowed, and `2^31` overflows a signed 32-bit |
213 | | // integer). But RFC 8536 does say that it *should* be in the range |
214 | | // `[-89999, 93599]`, which matches POSIX. In order to keep our offset |
215 | | // small, we stick roughly to what POSIX requires. |
216 | | // |
217 | | // Note that we support a slightly bigger range of offsets than Temporal. |
218 | | // Temporal seems to support only up to 23 hours, but we go up to 25 hours. |
219 | | // This is done to support POSIX time zone strings, which also require 25 |
220 | | // hours (plus the maximal minute/second components). |
221 | | (OffsetHours, i8, "time zone offset hours", -25, 25), |
222 | | (OffsetMinutes, i8, "time zone offset minutes", -59, 59), |
223 | | (OffsetSeconds, i8, "time zone offset seconds", -59, 59), |
224 | | ( |
225 | | OffsetTotalSeconds, |
226 | | i32, |
227 | | "time zone offset total seconds", |
228 | | -Self::MAX, |
229 | | (OffsetHours::MAX as i32 * SECS_PER_HOUR_32) |
230 | | + (OffsetMinutes::MAX as i32 * MINS_PER_HOUR_32) |
231 | | + OffsetSeconds::MAX as i32, |
232 | | ), |
233 | | (Second, i8, "second", 0, 59), |
234 | | (SignedDurationSeconds, i64, "signed duration seconds", i64::MIN, i64::MAX), |
235 | | (SpanYears, i16, "years", -Self::MAX, (Year::LEN - 1) as i16), |
236 | | (SpanMonths, i32, "months", -Self::MAX, SpanYears::MAX as i32 * 12), |
237 | | (SpanWeeks, i32, "weeks", -Self::MAX, SpanDays::MAX / DAYS_PER_WEEK_32), |
238 | | (SpanDays, i32, "days", -Self::MAX, SpanHours::MAX / HOURS_PER_CIVIL_DAY_32), |
239 | | (SpanHours, i32, "hours", -Self::MAX, (SpanMinutes::MAX / MINS_PER_HOUR) as i32), |
240 | | (SpanMinutes, i64, "minutes", -Self::MAX, SpanSeconds::MAX / SECS_PER_MIN), |
241 | | // The maximum number of seconds that can be expressed with a span. |
242 | | // |
243 | | // All of our span types (except for years and months, since they have |
244 | | // variable length even in civil datetimes) are defined in terms of this |
245 | | // constant. The way it's defined is a little odd, so let's break it down. |
246 | | // |
247 | | // Firstly, a span of seconds should be able to represent at least the |
248 | | // complete span supported by `Timestamp`. Thus, it's based off of |
249 | | // `UnixSeconds::LEN`. That is, a span should be able to represent the |
250 | | // value `UnixSeconds::MAX - UnixSeconds::MIN`. |
251 | | // |
252 | | // Secondly, a span should also be able to account for any amount of |
253 | | // possible time that a time zone offset might add or subtract to an |
254 | | // `Timestamp`. This also means it can account for any difference between |
255 | | // two `civil::DateTime` values. |
256 | | // |
257 | | // Thirdly, we would like our span to be divisible by |
258 | | // `SECONDS_PER_CIVIL_DAY`. This isn't strictly required, but it makes |
259 | | // defining boundaries a little smoother. If it weren't divisible, then the |
260 | | // lower bounds on some types would need to be adjusted by one. |
261 | | // |
262 | | // Note that neither the existence of this constant nor defining our |
263 | | // spans based on it impacts the correctness of doing arithmetic on zoned |
264 | | // instants. Arithmetic on zoned instants still uses "civil" spans, but the |
265 | | // length of time for some units (like a day) might vary. The arithmetic |
266 | | // for zoned instants accounts for this explicitly. But it still must obey |
267 | | // the limits set here. |
268 | | ( |
269 | | SpanSeconds, |
270 | | i64, |
271 | | "seconds", |
272 | | -Self::MAX, |
273 | | next_multiple_of( |
274 | | UnixSeconds::LEN as i64 |
275 | | + OffsetTotalSeconds::MAX as i64 |
276 | | + SECS_PER_CIVIL_DAY, |
277 | | SECS_PER_CIVIL_DAY, |
278 | | ), |
279 | | ), |
280 | | ( |
281 | | SpanMilliseconds, |
282 | | i64, |
283 | | "milliseconds", |
284 | | -Self::MAX, |
285 | | SpanSeconds::MAX * MILLIS_PER_SEC, |
286 | | ), |
287 | | ( |
288 | | SpanMicroseconds, |
289 | | i64, |
290 | | "microseconds", |
291 | | -Self::MAX, |
292 | | SpanMilliseconds::MAX * MICROS_PER_MILLI, |
293 | | ), |
294 | | (SpanMultiple, i64, "span multiple", i64::MIN + 1, i64::MAX), |
295 | | // A range of the allowed number of nanoseconds. |
296 | | // |
297 | | // For this, we cannot cover the full span of supported time instants since |
298 | | // `UnixSeconds::MAX * NANOSECONDS_PER_SECOND` cannot fit into 64-bits. We |
299 | | // could use a `i128`, but it doesn't seem worth it. |
300 | | // |
301 | | // Also note that our min is equal to -max, so that the total number of |
302 | | // values in this range is one less than the number of distinct `i64` |
303 | | // values. We do that so that the absolute value is always defined. |
304 | | (SpanNanoseconds, i64, "nanoseconds", i64::MIN + 1, i64::MAX), |
305 | | (SubsecNanosecond, i32, "subsecond nanosecond", 0, NANOS_PER_SEC_32 - 1), |
306 | | ( |
307 | | SignedSubsecNanosecond, |
308 | | i32, |
309 | | "subsecond nanosecond", |
310 | | -SubsecNanosecond::MAX, |
311 | | SubsecNanosecond::MAX, |
312 | | ), |
313 | | // The number of days from the Unix epoch for the Gregorian calendar. |
314 | | // |
315 | | // The range supported is based on the range of Unix timestamps that we |
316 | | // support. |
317 | | // |
318 | | // While I had originally used the "rate die" concept from Calendrical |
319 | | // Calculations, I found [Howard Hinnant's formulation][date-algorithms] |
320 | | // much more straight-forward. |
321 | | // |
322 | | // [date-algorithms]: http://howardhinnant.github.io/date_algorithms.html |
323 | | ( |
324 | | UnixEpochDays, |
325 | | i32, |
326 | | "Unix epoch days", |
327 | | (UnixSeconds::MIN+ OffsetTotalSeconds::MIN as i64).div_euclid(SECS_PER_CIVIL_DAY) as i32, |
328 | | (UnixSeconds::MAX + OffsetTotalSeconds::MAX as i64).div_euclid(SECS_PER_CIVIL_DAY) as i32, |
329 | | ), |
330 | | ( |
331 | | UnixMilliseconds, |
332 | | i64, |
333 | | "Unix timestamp milliseconds", |
334 | | UnixSeconds::MIN * MILLIS_PER_SEC, |
335 | | UnixSeconds::MAX * MILLIS_PER_SEC, |
336 | | ), |
337 | | ( |
338 | | UnixMicroseconds, |
339 | | i64, |
340 | | "Unix timestamp microseconds", |
341 | | UnixMilliseconds::MIN * MICROS_PER_MILLI, |
342 | | UnixMilliseconds::MAX * MICROS_PER_MILLI, |
343 | | ), |
344 | | // The range of Unix seconds supported by Jiff. |
345 | | // |
346 | | // This range should correspond to the first second of `Year::MIN` up |
347 | | // through (and including) the last second of `Year::MAX`. Actually |
348 | | // computing that is non-trivial, however, it can be computed easily enough |
349 | | // using Unix programs like `date`: |
350 | | // |
351 | | // ```text |
352 | | // $ TZ=0 date -d 'Mon Jan 1 12:00:00 AM -9999' +'%s' |
353 | | // date: invalid date ‘Mon Jan 1 12:00:00 AM -9999’ |
354 | | // $ TZ=0 date -d 'Fri Dec 31 23:59:59 9999' +'%s' |
355 | | // 253402300799 |
356 | | // ``` |
357 | | // |
358 | | // Well, almost easily enough. `date` apparently doesn't support negative |
359 | | // years. But it does support negative timestamps: |
360 | | // |
361 | | // ```text |
362 | | // $ TZ=0 date -d '@-377705116800' |
363 | | // Mon Jan 1 12:00:00 AM -9999 |
364 | | // $ TZ=0 date -d '@253402300799' |
365 | | // Fri Dec 31 11:59:59 PM 9999 |
366 | | // ``` |
367 | | // |
368 | | // With that said, we actually end up restricting the range a bit more |
369 | | // than what's above. Namely, what's above is what we support for civil |
370 | | // datetimes. Because of time zones, we need to choose whether all |
371 | | // `Timestamp` values can be infallibly converted to `civil::DateTime` |
372 | | // values, or whether all `civil::DateTime` values can be infallibly |
373 | | // converted to `Timestamp` values. I chose the former because getting |
374 | | // a civil datetime is important for formatting. If I didn't choose the |
375 | | // former, there would be some instants that could not be formatted. Thus, |
376 | | // we make room by shrinking the range of allowed instants by precisely the |
377 | | // maximum supported time zone offset. |
378 | | ( |
379 | | UnixSeconds, |
380 | | i64, |
381 | | "Unix timestamp seconds", |
382 | | -377705116800 - OffsetTotalSeconds::MIN as i64, |
383 | | 253402300799 - OffsetTotalSeconds::MAX as i64, |
384 | | ), |
385 | | (WeekNum, i8, "week-number", 0, 53), |
386 | | (WeekdayMondayZero, i8, "weekday (Monday 0-indexed)", 0, 6), |
387 | | (WeekdayMondayOne, i8, "weekday (Monday 1-indexed)", 1, 7), |
388 | | (WeekdaySundayZero, i8, "weekday (Sunday 0-indexed)", 0, 6), |
389 | | (WeekdaySundayOne, i8, "weekday (Sunday 1-indexed)", 1, 7), |
390 | | // The range of years supported by Jiff. |
391 | | // |
392 | | // This is ultimately where some of the other ranges (like `UnixSeconds`) |
393 | | // were determined from. That is, the range of years is the primary point |
394 | | // at which the space of supported time instants is derived from. If one |
395 | | // wanted to expand this range, you'd need to change it here and then |
396 | | // compute the corresponding min/max values for `UnixSeconds`. (Among other |
397 | | // things... Increasing the supported Jiff range is far more complicated |
398 | | // than just changing some ranges here.) |
399 | | (Year, i16, "year", -9999, 9999), |
400 | | (YearCE, i16, "CE year", 1, Year::MAX), |
401 | | (YearBCE, i16, "BCE year", 1, Year::MAX + 1), |
402 | | (YearTwoDigit, i16, "year (2 digits)", 0, 99), |
403 | | ( |
404 | | ZonedDayNanoseconds, |
405 | | i64, |
406 | | "nanoseconds (in one zoned datetime day)", |
407 | | ZonedDaySeconds::MIN as i64 * NANOS_PER_SEC, |
408 | | ZonedDaySeconds::MAX as i64 * NANOS_PER_SEC, |
409 | | ), |
410 | | // The number of seconds permitted in a single day. |
411 | | // |
412 | | // This is mostly just a "sensible" cap on what is possible. We allow one |
413 | | // day to span up to 7 civil days. |
414 | | // |
415 | | // It must also be at least 1 second long. |
416 | | ( |
417 | | ZonedDaySeconds, |
418 | | i32, |
419 | | "seconds (in one zoned datetime day)", |
420 | | 1, |
421 | | 7 * SECS_PER_CIVIL_DAY_32, |
422 | | ), |
423 | | } |
424 | | |
425 | | /// An interface for defining boundaries on integer values. |
426 | | pub(crate) trait Bounds: Sized { |
427 | | /// A short human readable description of the values represented by these |
428 | | /// bounds. |
429 | | const WHAT: &'static str; |
430 | | |
431 | | /// The minimum boundary value. |
432 | | const MIN: Self::Primitive; |
433 | | |
434 | | /// The maximum boundary value. |
435 | | const MAX: Self::Primitive; |
436 | | |
437 | | /// The primitive integer representation for this boundary type. |
438 | | /// |
439 | | /// This is generally the smallest primitive integer type that fits the |
440 | | /// minimum and maximum allowed values. |
441 | | // MSRV: Ideally this would be a private trait. On newer versions |
442 | | // of Rust (not sure when it started exactly), it's allowed but |
443 | | // comes with a warn-by-default lint. I would like it to be private |
444 | | // to avoid accidentally using it elsewhere, since it makes casts |
445 | | // between integers very easy. |
446 | | type Primitive: Primitive; |
447 | | |
448 | | // We provide `check` and `check128` to avoid manifesting 128-bit integers |
449 | | // in the vast majority of cases. While in theory the compiler should be |
450 | | // able to see through it, this is such a primitive and common operation |
451 | | // used throughout Jiff, that we specialize the overwhelmingly common case |
452 | | // for 64-bit integers under the presumption that 64-bit integers (and |
453 | | // smaller) are either always fast enough or are slower in environments |
454 | | // where we care less about performance. |
455 | | |
456 | | /// Create an error when a value is outside the bounds for this type. |
457 | | fn error() -> BoundsError; |
458 | | |
459 | | /// Converts the 64-bit integer provided into the primitive representation |
460 | | /// of these bounds. |
461 | | /// |
462 | | /// # Errors |
463 | | /// |
464 | | /// This returns an error if the given integer does not fit in the bounds |
465 | | /// prescribed by this trait implementation. |
466 | | /// |
467 | | /// # Panics |
468 | | /// |
469 | | /// This panics when `debug_assertions` are enabled if the bounds of |
470 | | /// this implementation exceed what is representable in an `i64`. In |
471 | | /// this case, callers must use `check128`. |
472 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
473 | 0 | fn check(n: impl Into<i64>) -> Result<Self::Primitive, BoundsError> { |
474 | | // These asserts confirm that we only call this routine when our |
475 | | // bounds fit into an i64. Otherwise, the `as_i64()` casts below |
476 | | // are incorrect. |
477 | 0 | debug_assert!((i128::from(i64::MIN)..=i128::from(i64::MAX)) |
478 | 0 | .contains(&Self::MIN.as_i128())); |
479 | 0 | debug_assert!((i128::from(i64::MIN)..=i128::from(i64::MAX)) |
480 | 0 | .contains(&Self::MAX.as_i128())); |
481 | | |
482 | 0 | let n = n.into(); |
483 | 0 | if !(Self::MIN.as_i64() <= n && n <= Self::MAX.as_i64()) { |
484 | 0 | return Err(Self::error()); |
485 | 0 | } |
486 | 0 | Ok(Self::Primitive::from_i64(n)) |
487 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixSeconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::LeapSecond as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMonths as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Increment32 as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::OffsetHours as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMinutes as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanSeconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::UnixSeconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::YearTwoDigit as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::OffsetMinutes as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::OffsetSeconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanNanoseconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMicroseconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanMilliseconds as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SubsecNanosecond as jiff::util::b::Bounds>::check::<i32> Unexecuted instantiation: <jiff::util::b::SubsecNanosecond as jiff::util::b::Bounds>::check::<u32> Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds as jiff::util::b::Bounds>::check::<i32> Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond as jiff::util::b::Bounds>::check::<i32> Unexecuted instantiation: <jiff::util::b::Day as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::Day as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Hour as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::Hour as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::check::<i16> Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Month as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::Month as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Hour12 as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Minute as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::Minute as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::Second as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::Second as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::YearCE as jiff::util::b::Bounds>::check::<i16> Unexecuted instantiation: <jiff::util::b::Century as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::ISOWeek as jiff::util::b::Bounds>::check::<i8> Unexecuted instantiation: <jiff::util::b::ISOWeek as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::ISOYear as jiff::util::b::Bounds>::check::<i16> Unexecuted instantiation: <jiff::util::b::ISOYear as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::WeekNum as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::YearBCE as jiff::util::b::Bounds>::check::<i16> Unexecuted instantiation: <jiff::util::b::SpanDays as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::DayOfYear as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanHours as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanWeeks as jiff::util::b::Bounds>::check::<i64> Unexecuted instantiation: <jiff::util::b::SpanYears as jiff::util::b::Bounds>::check::<i64> |
488 | | |
489 | | /// Converts the 128-bit integer provided into the primitive representation |
490 | | /// of these bounds. |
491 | | /// |
492 | | /// # Errors |
493 | | /// |
494 | | /// This returns an error if the given integer does not fit in the bounds |
495 | | /// prescribed by this trait implementation. |
496 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
497 | 0 | fn check128(n: impl Into<i128>) -> Result<Self::Primitive, BoundsError> { |
498 | 0 | let n = n.into(); |
499 | 0 | if !(Self::MIN.as_i128() <= n && n <= Self::MAX.as_i128()) { |
500 | 0 | return Err(Self::error()); |
501 | 0 | } |
502 | 0 | Ok(Self::Primitive::from_i128(n)) |
503 | 0 | } |
504 | | |
505 | | /// Checks whether the given integer, in the same primitive representation |
506 | | /// as this boundary type, is in bounds. |
507 | | /// |
508 | | /// # Errors |
509 | | /// |
510 | | /// This returns an error if the given integer does not fit in the bounds |
511 | | /// prescribed by this trait implementation. |
512 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
513 | 0 | fn check_self(n: Self::Primitive) -> Result<Self::Primitive, BoundsError> { |
514 | 0 | if !(Self::MIN <= n && n <= Self::MAX) { |
515 | 0 | return Err(Self::error()); |
516 | 0 | } |
517 | 0 | Ok(n) |
518 | 0 | } Unexecuted instantiation: <jiff::util::b::SpanMonths as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanMinutes as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanSeconds as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::UnixSeconds as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanNanoseconds as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanMicroseconds as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanMilliseconds as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanDays as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanHours as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanWeeks as jiff::util::b::Bounds>::check_self Unexecuted instantiation: <jiff::util::b::SpanYears as jiff::util::b::Bounds>::check_self |
519 | | |
520 | | /// Parses a 64-bit integer from the beginning to the end of the given |
521 | | /// slice of bytes. |
522 | | /// |
523 | | /// Note that this can never parse a negative integer since it doesn't |
524 | | /// look for a sign. On success, the integer returned is always positive. |
525 | | /// |
526 | | /// # Errors |
527 | | /// |
528 | | /// If the given slice is not a valid integer (i.e., overflow or contains |
529 | | /// anything other than `[0-9]`) or is not in the bounds for this trait |
530 | | /// implementation, then an error is returned. |
531 | | /// |
532 | | /// Note that the error can either be a parsing error or it can be a |
533 | | /// boundary error. |
534 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
535 | 0 | fn parse(bytes: &[u8]) -> Result<Self::Primitive, Error> { |
536 | 0 | Ok(Self::check(crate::util::parse::i64(bytes)?)?) |
537 | 0 | } Unexecuted instantiation: <jiff::util::b::LeapSecond as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::OffsetHours as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::OffsetMinutes as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::OffsetSeconds as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::Day as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::Hour as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::Month as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::Minute as jiff::util::b::Bounds>::parse Unexecuted instantiation: <jiff::util::b::ISOWeek as jiff::util::b::Bounds>::parse |
538 | | |
539 | | /// Performs checked addition using this boundary type's primitive |
540 | | /// representation. |
541 | | /// |
542 | | /// # Errors |
543 | | /// |
544 | | /// If the result exceeds the boundaries of the primitive type or of the |
545 | | /// declared range for this type, then an error is returned. |
546 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
547 | 0 | fn checked_add( |
548 | 0 | n1: Self::Primitive, |
549 | 0 | n2: Self::Primitive, |
550 | 0 | ) -> Result<Self::Primitive, BoundsError> { |
551 | 0 | Self::check_self(n1.checked_add(n2).ok_or_else(Self::error)?) |
552 | 0 | } Unexecuted instantiation: <jiff::util::b::SpanMonths as jiff::util::b::Bounds>::checked_add Unexecuted instantiation: <jiff::util::b::UnixSeconds as jiff::util::b::Bounds>::checked_add Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff::util::b::Bounds>::checked_add Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::checked_add |
553 | | |
554 | | /// Performs checked subtraction using this boundary type's primitive |
555 | | /// representation. |
556 | | /// |
557 | | /// # Errors |
558 | | /// |
559 | | /// If the result exceeds the boundaries of the primitive type or of the |
560 | | /// declared range for this type, then an error is returned. |
561 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
562 | 0 | fn checked_sub( |
563 | 0 | n1: Self::Primitive, |
564 | 0 | n2: Self::Primitive, |
565 | 0 | ) -> Result<Self::Primitive, BoundsError> { |
566 | 0 | Self::check_self(n1.checked_sub(n2).ok_or_else(Self::error)?) |
567 | 0 | } Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff::util::b::Bounds>::checked_sub Unexecuted instantiation: <jiff::util::b::Year as jiff::util::b::Bounds>::checked_sub |
568 | | |
569 | | /// Performs checked multiplication using this boundary type's primitive |
570 | | /// representation. |
571 | | /// |
572 | | /// # Errors |
573 | | /// |
574 | | /// If the result exceeds the boundaries of the primitive type or of the |
575 | | /// declared range for this type, then an error is returned. |
576 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
577 | 0 | fn checked_mul( |
578 | 0 | n1: Self::Primitive, |
579 | 0 | n2: Self::Primitive, |
580 | 0 | ) -> Result<Self::Primitive, BoundsError> { |
581 | 0 | Self::check_self(n1.checked_mul(n2).ok_or_else(Self::error)?) |
582 | 0 | } Unexecuted instantiation: <jiff::util::b::SpanMonths as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMinutes as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanSeconds as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanNanoseconds as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMicroseconds as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanMilliseconds as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanDays as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanHours as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanWeeks as jiff::util::b::Bounds>::checked_mul Unexecuted instantiation: <jiff::util::b::SpanYears as jiff::util::b::Bounds>::checked_mul |
583 | | } |
584 | | |
585 | | /// A simple trait for making `int as int` usable in a generic context. |
586 | | /// |
587 | | /// All of these methods require callers to ensure the cast is correct. |
588 | | pub(crate) trait Primitive: |
589 | | Clone |
590 | | + Copy |
591 | | + Eq |
592 | | + PartialEq |
593 | | + PartialOrd |
594 | | + Ord |
595 | | + core::fmt::Debug |
596 | | + core::fmt::Display |
597 | | { |
598 | | fn as_i8(self) -> i8; |
599 | | fn as_i16(self) -> i16; |
600 | | fn as_i32(self) -> i32; |
601 | | fn as_i64(self) -> i64; |
602 | | fn as_i128(self) -> i128; |
603 | | |
604 | | fn from_i8(n: i8) -> Self; |
605 | | fn from_i16(n: i16) -> Self; |
606 | | fn from_i32(n: i32) -> Self; |
607 | | fn from_i64(n: i64) -> Self; |
608 | | fn from_i128(n: i128) -> Self; |
609 | | |
610 | | fn checked_add(self, n: Self) -> Option<Self>; |
611 | | fn checked_sub(self, n: Self) -> Option<Self>; |
612 | | fn checked_mul(self, n: Self) -> Option<Self>; |
613 | | } |
614 | | |
615 | | macro_rules! impl_primitive { |
616 | | ($($intty:ty),*) => { |
617 | | $( |
618 | | impl Primitive for $intty { |
619 | 0 | fn as_i8(self) -> i8 { self as i8 }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::as_i8 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::as_i8 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::as_i8 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::as_i8 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::as_i8 |
620 | 0 | fn as_i16(self) -> i16 { self as i16 }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::as_i16 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::as_i16 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::as_i16 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::as_i16 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::as_i16 |
621 | 0 | fn as_i32(self) -> i32 { self as i32 }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::as_i32 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::as_i32 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::as_i32 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::as_i32 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::as_i32 |
622 | 0 | fn as_i64(self) -> i64 { self as i64 }Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::as_i64 Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::as_i64 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::as_i64 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::as_i64 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::as_i64 |
623 | 0 | fn as_i128(self) -> i128 { self as i128 }Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::as_i128 Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::as_i128 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::as_i128 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::as_i128 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::as_i128 |
624 | | |
625 | 0 | fn from_i8(n: i8) -> Self { n as $intty }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::from_i8 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::from_i8 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::from_i8 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::from_i8 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::from_i8 |
626 | 0 | fn from_i16(n: i16) -> Self { n as $intty }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::from_i16 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::from_i16 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::from_i16 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::from_i16 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::from_i16 |
627 | 0 | fn from_i32(n: i32) -> Self { n as $intty }Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::from_i32 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::from_i32 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::from_i32 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::from_i32 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::from_i32 |
628 | 0 | fn from_i64(n: i64) -> Self { n as $intty }Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::from_i64 Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::from_i64 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::from_i64 Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::from_i64 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::from_i64 |
629 | 0 | fn from_i128(n: i128) -> Self { n as $intty }Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::from_i128 Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::from_i128 Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::from_i128 Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::from_i128 Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::from_i128 |
630 | | |
631 | 0 | fn checked_add(self, n: $intty) -> Option<$intty> { |
632 | 0 | <$intty>::checked_add(self, n) |
633 | 0 | } Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::checked_add Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::checked_add Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::checked_add Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::checked_add Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::checked_add |
634 | | |
635 | 0 | fn checked_sub(self, n: $intty) -> Option<$intty> { |
636 | 0 | <$intty>::checked_sub(self, n) |
637 | 0 | } Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::checked_sub Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::checked_sub Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::checked_sub Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::checked_sub Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::checked_sub |
638 | | |
639 | 0 | fn checked_mul(self, n: $intty) -> Option<$intty> { |
640 | 0 | <$intty>::checked_mul(self, n) |
641 | 0 | } Unexecuted instantiation: <i8 as jiff::util::b::Primitive>::checked_mul Unexecuted instantiation: <i16 as jiff::util::b::Primitive>::checked_mul Unexecuted instantiation: <i32 as jiff::util::b::Primitive>::checked_mul Unexecuted instantiation: <i64 as jiff::util::b::Primitive>::checked_mul Unexecuted instantiation: <i128 as jiff::util::b::Primitive>::checked_mul |
642 | | } |
643 | | )* |
644 | | } |
645 | | } |
646 | | |
647 | | impl_primitive!(i8, i16, i32, i64, i128); |
648 | | |
649 | | impl From<BoundsError> for Error { |
650 | 0 | fn from(err: BoundsError) -> Error { |
651 | 0 | Error::bounds(err) |
652 | 0 | } |
653 | | } |
654 | | |
655 | | impl crate::error::IntoError for BoundsError { |
656 | 0 | fn into_error(self) -> Error { |
657 | 0 | self.into() |
658 | 0 | } |
659 | | } |
660 | | |
661 | | pub(crate) struct RawBoundsError<B>(core::marker::PhantomData<B>); |
662 | | |
663 | | impl<B> RawBoundsError<B> { |
664 | 0 | const fn new() -> RawBoundsError<B> { |
665 | 0 | RawBoundsError(core::marker::PhantomData) |
666 | 0 | } Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedDurationSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::LeapSecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Nanosecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::NthWeekday>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMonths>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment32>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Microsecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Millisecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetHours>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMinutes>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMultiple>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearTwoDigit>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetMinutes>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixEpochDays>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDaySecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanNanoseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDaySeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMicroseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMilliseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SubsecNanosecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMicroseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMilliseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayOne>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayOne>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayZero>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayZero>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDayNanosecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetTotalSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDayNanoseconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedDurationSeconds>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedSubsecNanosecond>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Day>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Year>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Month>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour12>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Minute>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Second>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearCE>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Century>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOWeek>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOYear>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekNum>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearBCE>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanDays>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::DayOfYear>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanHours>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanWeeks>>::new Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanYears>>::new |
667 | | } |
668 | | |
669 | | impl<B> Clone for RawBoundsError<B> { |
670 | 0 | fn clone(&self) -> RawBoundsError<B> { |
671 | 0 | RawBoundsError::new() |
672 | 0 | } |
673 | | } |
674 | | |
675 | | impl<B, P> core::fmt::Debug for RawBoundsError<B> |
676 | | where |
677 | | B: Bounds<Primitive = P>, |
678 | | P: core::fmt::Debug, |
679 | | { |
680 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
681 | 0 | f.debug_struct("RawBoundsError") |
682 | 0 | .field("what", &B::WHAT) |
683 | 0 | .field("min", &B::MIN) |
684 | 0 | .field("max", &B::MAX) |
685 | 0 | .finish() |
686 | 0 | } Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::LeapSecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Nanosecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::NthWeekday> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMonths> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment32> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Microsecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Millisecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetHours> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMinutes> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanSeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixSeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMultiple> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearTwoDigit> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetMinutes> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetSeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixEpochDays> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDaySecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanNanoseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDaySeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMicroseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMilliseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SubsecNanosecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMicroseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMilliseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayOne> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayOne> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayZero> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayZero> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDayNanosecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetTotalSeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDayNanoseconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedDurationSeconds> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedSubsecNanosecond> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Day> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Year> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Month> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour12> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Minute> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Second> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearCE> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Century> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOWeek> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOYear> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekNum> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearBCE> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanDays> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::DayOfYear> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanHours> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanWeeks> as core::fmt::Debug>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanYears> as core::fmt::Debug>::fmt |
687 | | } |
688 | | |
689 | | impl<B, P> core::fmt::Display for RawBoundsError<B> |
690 | | where |
691 | | B: Bounds<Primitive = P>, |
692 | | P: core::fmt::Display, |
693 | | { |
694 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
695 | 0 | write!( |
696 | 0 | f, |
697 | 0 | "parameter '{what}' is not in the required range of {min}..={max}", |
698 | | what = B::WHAT, |
699 | 0 | min = B::MIN, |
700 | 0 | max = B::MAX, |
701 | | ) |
702 | 0 | } Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::LeapSecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Nanosecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::NthWeekday> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMonths> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment32> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Microsecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Millisecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetHours> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMinutes> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanSeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixSeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMultiple> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearTwoDigit> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetMinutes> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetSeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixEpochDays> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDaySecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanNanoseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDaySeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMicroseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanMilliseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SubsecNanosecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMicroseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::UnixMilliseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayOne> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayOne> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdayMondayZero> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekdaySundayZero> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::CivilDayNanosecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::OffsetTotalSeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ZonedDayNanoseconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedDurationSeconds> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SignedSubsecNanosecond> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Day> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Year> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Month> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Hour12> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Minute> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Second> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearCE> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Century> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOWeek> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::ISOYear> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::WeekNum> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::YearBCE> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanDays> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::DayOfYear> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::Increment> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanHours> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanWeeks> as core::fmt::Display>::fmt Unexecuted instantiation: <jiff::util::b::RawBoundsError<jiff::util::b::SpanYears> as core::fmt::Display>::fmt |
703 | | } |
704 | | |
705 | | /// Like `BoundsError`, but maintained manually. |
706 | | /// |
707 | | /// This is useful for range errors outside of the framework above. |
708 | | #[derive(Clone, Debug)] |
709 | | pub(crate) enum SpecialBoundsError { |
710 | | UnixNanoseconds, |
711 | | SignedDurationFloatOutOfRangeF32, |
712 | | SignedDurationFloatOutOfRangeF64, |
713 | | UnsignedDurationSeconds, |
714 | | } |
715 | | |
716 | | impl core::fmt::Display for SpecialBoundsError { |
717 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
718 | | use self::SpecialBoundsError::*; |
719 | | |
720 | 0 | let (what, min, max) = match *self { |
721 | 0 | UnixNanoseconds => ( |
722 | 0 | "Unix timestamp nanoseconds", |
723 | 0 | UnixMicroseconds::MIN as i128 * (NANOS_PER_MICRO as i128), |
724 | 0 | UnixMicroseconds::MAX as i128 * (NANOS_PER_MICRO as i128), |
725 | 0 | ), |
726 | 0 | UnsignedDurationSeconds => ( |
727 | 0 | "unsigned duration seconds", |
728 | 0 | u64::MIN as i128, |
729 | 0 | u64::MAX as i128, |
730 | 0 | ), |
731 | | SignedDurationFloatOutOfRangeF32 => { |
732 | 0 | return write!( |
733 | 0 | f, |
734 | 0 | "parameter 'floating point seconds' is not in \ |
735 | 0 | the required range of {min}..={max}", |
736 | | min = i64::MIN as f32, |
737 | | max = i64::MAX as f32, |
738 | | ); |
739 | | } |
740 | | SignedDurationFloatOutOfRangeF64 => { |
741 | 0 | return write!( |
742 | 0 | f, |
743 | 0 | "parameter 'floating point seconds' is not in \ |
744 | 0 | the required range of {min}..={max}", |
745 | | min = i64::MIN as f64, |
746 | | max = i64::MAX as f64, |
747 | | ); |
748 | | } |
749 | | }; |
750 | 0 | write!( |
751 | 0 | f, |
752 | 0 | "parameter '{what}' is not in the required range of {min}..={max}", |
753 | | ) |
754 | 0 | } |
755 | | } |
756 | | |
757 | | impl From<SpecialBoundsError> for Error { |
758 | 0 | fn from(err: SpecialBoundsError) -> Error { |
759 | 0 | Error::special_bounds(err) |
760 | 0 | } |
761 | | } |
762 | | |
763 | | impl crate::error::IntoError for SpecialBoundsError { |
764 | 0 | fn into_error(self) -> Error { |
765 | 0 | self.into() |
766 | 0 | } |
767 | | } |
768 | | |
769 | | /// A representation of a numeric sign. |
770 | | /// |
771 | | /// Its `Display` impl emits the ASCII minus sign, `-` when this |
772 | | /// is negative. It emits the empty string in all other cases. |
773 | | #[derive( |
774 | | Clone, Copy, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord, |
775 | | )] |
776 | | #[repr(i8)] |
777 | | pub(crate) enum Sign { |
778 | | #[default] |
779 | | Zero = 0, |
780 | | Positive = 1, |
781 | | Negative = -1, |
782 | | } |
783 | | |
784 | | impl Sign { |
785 | 0 | pub(crate) fn is_zero(self) -> bool { |
786 | 0 | matches!(self, Sign::Zero) |
787 | 0 | } |
788 | | |
789 | 0 | pub(crate) fn is_positive(self) -> bool { |
790 | 0 | matches!(self, Sign::Positive) |
791 | 0 | } |
792 | | |
793 | 0 | pub(crate) fn is_negative(self) -> bool { |
794 | 0 | matches!(self, Sign::Negative) |
795 | 0 | } |
796 | | |
797 | 0 | pub(crate) fn signum(self) -> i8 { |
798 | 0 | self.as_i8() |
799 | 0 | } |
800 | | |
801 | 0 | pub(crate) fn as_i8(self) -> i8 { |
802 | 0 | self as i8 |
803 | 0 | } |
804 | | |
805 | 0 | pub(crate) fn as_i16(self) -> i16 { |
806 | 0 | i16::from(self.as_i8()) |
807 | 0 | } |
808 | | |
809 | 0 | pub(crate) fn as_i32(self) -> i32 { |
810 | 0 | i32::from(self.as_i8()) |
811 | 0 | } |
812 | | |
813 | 0 | pub(crate) fn as_i64(self) -> i64 { |
814 | 0 | i64::from(self.as_i8()) |
815 | 0 | } |
816 | | |
817 | 0 | pub(crate) fn as_i128(self) -> i128 { |
818 | 0 | i128::from(self.as_i8()) |
819 | 0 | } |
820 | | |
821 | 0 | pub(crate) fn from_ordinals<T: Ord>(t1: T, t2: T) -> Sign { |
822 | | use core::cmp::Ordering::*; |
823 | 0 | match t1.cmp(&t2) { |
824 | 0 | Less => Sign::Negative, |
825 | 0 | Equal => Sign::Zero, |
826 | 0 | Greater => Sign::Positive, |
827 | | } |
828 | 0 | } Unexecuted instantiation: <jiff::util::b::Sign>::from_ordinals::<jiff::civil::date::Date> Unexecuted instantiation: <jiff::util::b::Sign>::from_ordinals::<jiff::civil::time::Time> Unexecuted instantiation: <jiff::util::b::Sign>::from_ordinals::<&jiff::zoned::Zoned> |
829 | | } |
830 | | |
831 | | impl core::ops::Neg for Sign { |
832 | | type Output = Sign; |
833 | | |
834 | 0 | fn neg(self) -> Sign { |
835 | 0 | match self { |
836 | 0 | Sign::Positive => Sign::Negative, |
837 | 0 | Sign::Zero => Sign::Zero, |
838 | 0 | Sign::Negative => Sign::Positive, |
839 | | } |
840 | 0 | } |
841 | | } |
842 | | |
843 | | impl From<i8> for Sign { |
844 | 0 | fn from(n: i8) -> Sign { |
845 | 0 | Sign::from(i64::from(n)) |
846 | 0 | } |
847 | | } |
848 | | |
849 | | impl From<i16> for Sign { |
850 | 0 | fn from(n: i16) -> Sign { |
851 | 0 | Sign::from(i64::from(n)) |
852 | 0 | } |
853 | | } |
854 | | |
855 | | impl From<i32> for Sign { |
856 | 0 | fn from(n: i32) -> Sign { |
857 | 0 | Sign::from(i64::from(n)) |
858 | 0 | } |
859 | | } |
860 | | |
861 | | impl From<i64> for Sign { |
862 | 0 | fn from(n: i64) -> Sign { |
863 | 0 | if n == 0 { |
864 | 0 | Sign::Zero |
865 | 0 | } else if n > 0 { |
866 | 0 | Sign::Positive |
867 | | } else { |
868 | 0 | Sign::Negative |
869 | | } |
870 | 0 | } |
871 | | } |
872 | | |
873 | | impl From<i128> for Sign { |
874 | 0 | fn from(n: i128) -> Sign { |
875 | 0 | if n == 0 { |
876 | 0 | Sign::Zero |
877 | 0 | } else if n > 0 { |
878 | 0 | Sign::Positive |
879 | | } else { |
880 | 0 | Sign::Negative |
881 | | } |
882 | 0 | } |
883 | | } |
884 | | |
885 | | impl From<f64> for Sign { |
886 | 0 | fn from(n: f64) -> Sign { |
887 | | use core::num::FpCategory::*; |
888 | | |
889 | | // This is a little odd, but we want +/- 0 to |
890 | | // always have a sign of zero, so as to be consistent |
891 | | // with how we deal with signed integers. |
892 | | // |
893 | | // As for NaN... It should generally be a bug if |
894 | | // Jiff ever materializes a NaN. Notably, I do not |
895 | | // believe there are any APIs in which a float is |
896 | | // given from the caller. Jiff only ever uses them |
897 | | // internally or returns them. So if we get a NaN, |
898 | | // it's on us. If we do, just assign it a zero sign? |
899 | 0 | if matches!(n.classify(), Nan | Zero) { |
900 | 0 | Sign::Zero |
901 | 0 | } else if n.is_sign_positive() { |
902 | 0 | Sign::Positive |
903 | | } else { |
904 | 0 | Sign::Negative |
905 | | } |
906 | 0 | } |
907 | | } |
908 | | |
909 | | impl From<SignedDuration> for Sign { |
910 | 0 | fn from(n: SignedDuration) -> Sign { |
911 | 0 | if n.is_zero() { |
912 | 0 | Sign::Zero |
913 | 0 | } else if n.is_positive() { |
914 | 0 | Sign::Positive |
915 | | } else { |
916 | 0 | Sign::Negative |
917 | | } |
918 | 0 | } |
919 | | } |
920 | | |
921 | | impl core::ops::Mul<Sign> for Sign { |
922 | | type Output = Sign; |
923 | 0 | fn mul(self, rhs: Sign) -> Sign { |
924 | 0 | match (self, rhs) { |
925 | 0 | (Sign::Zero, _) | (_, Sign::Zero) => Sign::Zero, |
926 | 0 | (Sign::Positive, Sign::Positive) => Sign::Positive, |
927 | 0 | (Sign::Negative, Sign::Negative) => Sign::Positive, |
928 | 0 | (Sign::Positive, Sign::Negative) => Sign::Negative, |
929 | 0 | (Sign::Negative, Sign::Positive) => Sign::Negative, |
930 | | } |
931 | 0 | } |
932 | | } |
933 | | |
934 | | impl core::ops::Mul<i8> for Sign { |
935 | | type Output = i8; |
936 | 0 | fn mul(self, n: i8) -> i8 { |
937 | 0 | self.as_i8() * n |
938 | 0 | } |
939 | | } |
940 | | |
941 | | impl core::ops::Mul<Sign> for i8 { |
942 | | type Output = i8; |
943 | 0 | fn mul(self, n: Sign) -> i8 { |
944 | 0 | self * n.as_i8() |
945 | 0 | } |
946 | | } |
947 | | |
948 | | impl core::ops::Mul<i16> for Sign { |
949 | | type Output = i16; |
950 | 0 | fn mul(self, n: i16) -> i16 { |
951 | 0 | self.as_i16() * n |
952 | 0 | } |
953 | | } |
954 | | |
955 | | impl core::ops::Mul<Sign> for i16 { |
956 | | type Output = i16; |
957 | 0 | fn mul(self, n: Sign) -> i16 { |
958 | 0 | self * n.as_i16() |
959 | 0 | } |
960 | | } |
961 | | |
962 | | impl core::ops::Mul<i32> for Sign { |
963 | | type Output = i32; |
964 | 0 | fn mul(self, n: i32) -> i32 { |
965 | 0 | self.as_i32() * n |
966 | 0 | } |
967 | | } |
968 | | |
969 | | impl core::ops::Mul<Sign> for i32 { |
970 | | type Output = i32; |
971 | 0 | fn mul(self, n: Sign) -> i32 { |
972 | 0 | self * n.as_i32() |
973 | 0 | } |
974 | | } |
975 | | |
976 | | impl core::ops::Mul<i64> for Sign { |
977 | | type Output = i64; |
978 | 0 | fn mul(self, n: i64) -> i64 { |
979 | 0 | self.as_i64() * n |
980 | 0 | } |
981 | | } |
982 | | |
983 | | impl core::ops::Mul<Sign> for i64 { |
984 | | type Output = i64; |
985 | 0 | fn mul(self, n: Sign) -> i64 { |
986 | 0 | self * n.as_i64() |
987 | 0 | } |
988 | | } |
989 | | |
990 | | impl core::ops::Mul<i128> for Sign { |
991 | | type Output = i128; |
992 | 0 | fn mul(self, n: i128) -> i128 { |
993 | 0 | self.as_i128() * n |
994 | 0 | } |
995 | | } |
996 | | |
997 | | impl core::ops::Mul<Sign> for i128 { |
998 | | type Output = i128; |
999 | 0 | fn mul(self, n: Sign) -> i128 { |
1000 | 0 | self * n.as_i128() |
1001 | 0 | } |
1002 | | } |
1003 | | |
1004 | | impl core::fmt::Display for Sign { |
1005 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
1006 | 0 | if self.is_negative() { |
1007 | 0 | f.write_str("-") |
1008 | | } else { |
1009 | 0 | Ok(()) |
1010 | | } |
1011 | 0 | } |
1012 | | } |
1013 | | |
1014 | | mod checkc { |
1015 | | use super::{Bounds, RawBoundsError}; |
1016 | | |
1017 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
1018 | 0 | pub(super) const fn i8<B>(n: i64) -> Result<i8, RawBoundsError<B>> |
1019 | 0 | where |
1020 | 0 | B: Bounds<Primitive = i8>, |
1021 | | { |
1022 | | // These asserts confirm that we only call this routine |
1023 | | // when our bounds fit into an i64. Otherwise, the |
1024 | | // `as` casts below are incorrect. |
1025 | 0 | debug_assert!( |
1026 | 0 | (i64::MIN as i128) <= (B::MIN as i128) |
1027 | 0 | && (B::MIN as i128) <= (i64::MAX as i128), |
1028 | | ); |
1029 | 0 | debug_assert!( |
1030 | 0 | (i64::MIN as i128) <= (B::MAX as i128) |
1031 | 0 | && (B::MAX as i128) <= (i64::MAX as i128), |
1032 | | ); |
1033 | | |
1034 | 0 | if !((B::MIN as i64) <= n && n <= (B::MAX as i64)) { |
1035 | 0 | return Err(RawBoundsError::new()); |
1036 | 0 | } |
1037 | 0 | Ok(n as i8) |
1038 | 0 | } Unexecuted instantiation: jiff::util::b::checkc::i8::<jiff::util::b::OffsetHours> Unexecuted instantiation: jiff::util::b::checkc::i8::<jiff::util::b::Hour> Unexecuted instantiation: jiff::util::b::checkc::i8::<jiff::util::b::Minute> Unexecuted instantiation: jiff::util::b::checkc::i8::<jiff::util::b::Second> |
1039 | | |
1040 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
1041 | 0 | pub(super) const fn i16<B>(n: i64) -> Result<i16, RawBoundsError<B>> |
1042 | 0 | where |
1043 | 0 | B: Bounds<Primitive = i16>, |
1044 | | { |
1045 | | // These asserts confirm that we only call this routine |
1046 | | // when our bounds fit into an i64. Otherwise, the |
1047 | | // `as` casts below are incorrect. |
1048 | 0 | debug_assert!( |
1049 | 0 | (i64::MIN as i128) <= (B::MIN as i128) |
1050 | 0 | && (B::MIN as i128) <= (i64::MAX as i128), |
1051 | | ); |
1052 | 0 | debug_assert!( |
1053 | 0 | (i64::MIN as i128) <= (B::MAX as i128) |
1054 | 0 | && (B::MAX as i128) <= (i64::MAX as i128), |
1055 | | ); |
1056 | | |
1057 | 0 | if !((B::MIN as i64) <= n && n <= (B::MAX as i64)) { |
1058 | 0 | return Err(RawBoundsError::new()); |
1059 | 0 | } |
1060 | 0 | Ok(n as i16) |
1061 | 0 | } |
1062 | | |
1063 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
1064 | 0 | pub(super) const fn i32<B>(n: i64) -> Result<i32, RawBoundsError<B>> |
1065 | 0 | where |
1066 | 0 | B: Bounds<Primitive = i32>, |
1067 | | { |
1068 | | // These asserts confirm that we only call this routine |
1069 | | // when our bounds fit into an i64. Otherwise, the |
1070 | | // `as` casts below are incorrect. |
1071 | 0 | debug_assert!( |
1072 | 0 | (i64::MIN as i128) <= (B::MIN as i128) |
1073 | 0 | && (B::MIN as i128) <= (i64::MAX as i128), |
1074 | | ); |
1075 | 0 | debug_assert!( |
1076 | 0 | (i64::MIN as i128) <= (B::MAX as i128) |
1077 | 0 | && (B::MAX as i128) <= (i64::MAX as i128), |
1078 | | ); |
1079 | | |
1080 | 0 | if !((B::MIN as i64) <= n && n <= (B::MAX as i64)) { |
1081 | 0 | return Err(RawBoundsError::new()); |
1082 | 0 | } |
1083 | 0 | Ok(n as i32) |
1084 | 0 | } Unexecuted instantiation: jiff::util::b::checkc::i32::<jiff::util::b::OffsetTotalSeconds> Unexecuted instantiation: jiff::util::b::checkc::i32::<jiff::util::b::SubsecNanosecond> Unexecuted instantiation: jiff::util::b::checkc::i32::<jiff::util::b::SignedSubsecNanosecond> |
1085 | | |
1086 | | #[cfg_attr(feature = "perf-inline", inline(always))] |
1087 | 0 | pub(super) const fn i64<B>(n: i64) -> Result<i64, RawBoundsError<B>> |
1088 | 0 | where |
1089 | 0 | B: Bounds<Primitive = i64>, |
1090 | | { |
1091 | | // These asserts confirm that we only call this routine |
1092 | | // when our bounds fit into an i64. Otherwise, the |
1093 | | // `as` casts below are incorrect. |
1094 | 0 | debug_assert!( |
1095 | 0 | (i64::MIN as i128) <= (B::MIN as i128) |
1096 | 0 | && (B::MIN as i128) <= (i64::MAX as i128), |
1097 | | ); |
1098 | 0 | debug_assert!( |
1099 | 0 | (i64::MIN as i128) <= (B::MAX as i128) |
1100 | 0 | && (B::MAX as i128) <= (i64::MAX as i128), |
1101 | | ); |
1102 | | |
1103 | 0 | if !(B::MIN <= n && n <= B::MAX) { |
1104 | 0 | return Err(RawBoundsError::new()); |
1105 | 0 | } |
1106 | 0 | Ok(n) |
1107 | 0 | } |
1108 | | } |
1109 | | |
1110 | | /// Computes the next multiple of `rhs` that is greater than or equal to `lhs`. |
1111 | | /// |
1112 | | /// Taken from: |
1113 | | /// https://github.com/rust-lang/rust/blob/eff958c59e8c07ba0515e164b825c9001b242294/library/core/src/num/int_macros.rs |
1114 | 0 | const fn next_multiple_of(lhs: i64, rhs: i64) -> i64 { |
1115 | | // This would otherwise fail when calculating `r` when self == T::MIN. |
1116 | 0 | if rhs == -1 { |
1117 | 0 | return lhs; |
1118 | 0 | } |
1119 | | |
1120 | 0 | let r = lhs % rhs; |
1121 | 0 | let m = if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) { r + rhs } else { r }; |
1122 | 0 | if m == 0 { |
1123 | 0 | lhs |
1124 | | } else { |
1125 | 0 | lhs + (rhs - m) |
1126 | | } |
1127 | 0 | } |
1128 | | |
1129 | | #[cfg(test)] |
1130 | | mod tests { |
1131 | | use alloc::string::ToString; |
1132 | | |
1133 | | use super::*; |
1134 | | |
1135 | | #[test] |
1136 | | fn size_of_bounds_error() { |
1137 | | // It's okay if this grows, but I wrote this test initially |
1138 | | // to confirm that a `BoundsError` is very small. (Since it's |
1139 | | // just a bunch of variants of ZSTs.) |
1140 | | assert_eq!(1, core::mem::size_of::<BoundsError>()); |
1141 | | } |
1142 | | |
1143 | | #[test] |
1144 | | fn basic_error_functionality() { |
1145 | | let err = Year::check(10_000).unwrap_err(); |
1146 | | assert_eq!( |
1147 | | err.to_string(), |
1148 | | "parameter 'year' is not in the required range of -9999..=9999", |
1149 | | ); |
1150 | | } |
1151 | | } |