Coverage Report

Created: 2026-08-05 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-0.2.35/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
use jcore::{
9
    bounds::{self, const_check, Bounds, RawBoundsError},
10
    constants as c,
11
};
12
13
use crate::Error;
14
15
/// Writes the definition of a single boundary type.
16
///
17
/// When only the name and type are given, then this copies the `WHAT`,
18
/// `MIN` and `MAX` definitions from `jcore`. This avoids copying the specific
19
/// range values and maintains a single point of truth.
20
macro_rules! define_one_boundary_type {
21
    (
22
        // The name of the boundary type.
23
        $name:ident,
24
        // The underlying primitive type. This is usually, but not always,
25
        // the smallest signed primitive integer type that can represent both
26
        // the minimum and maximum boundary values.
27
        $ty:ident,
28
        // A short human readable description that appears in error messages
29
        // when the boundaries of this type are violated.
30
        $what:expr,
31
        // The minimum value.
32
        $min:expr,
33
        // The maximum value.
34
        $max:expr $(,)?
35
    ) => {
36
        pub(crate) struct $name(());
37
38
        impl Bounds for $name {
39
            const WHAT: &'static str = $what;
40
            const MIN: Self::Primitive = $min;
41
            const MAX: Self::Primitive = $max;
42
            type Primitive = $ty;
43
            type Error = BoundsError;
44
45
            #[cold]
46
            #[inline(never)]
47
9.86k
            fn error() -> BoundsError {
48
9.86k
                Self::error()
49
9.86k
            }
<jiff::util::b::SpanMinutes as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
338
            fn error() -> BoundsError {
48
338
                Self::error()
49
338
            }
<jiff::util::b::SpanSeconds as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
386
            fn error() -> BoundsError {
48
386
                Self::error()
49
386
            }
Unexecuted instantiation: <jiff::util::b::SpanMilliseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::SpanMicroseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::SpanMultiple as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::YearCE as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::YearBCE as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::YearTwoDigit as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::ZonedDayNanoseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::ZonedDaySeconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::SpanNanoseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::SubsecNanosecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochDays as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochMilliseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::WeekNum as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne as jiff_core::bounds::Bounds>::error
<jiff::util::b::Year as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
90
            fn error() -> BoundsError {
48
90
                Self::error()
49
90
            }
Unexecuted instantiation: <jiff::util::b::Century as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::CivilDaySecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::Nanosecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::NthWeekday as jiff_core::bounds::Bounds>::error
<jiff::util::b::OffsetHours as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
49
            fn error() -> BoundsError {
48
49
                Self::error()
49
49
            }
<jiff::util::b::OffsetMinutes as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
17
            fn error() -> BoundsError {
48
17
                Self::error()
49
17
            }
<jiff::util::b::OffsetSeconds as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
10
            fn error() -> BoundsError {
48
10
                Self::error()
49
10
            }
Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds as jiff_core::bounds::Bounds>::error
<jiff::util::b::Second as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
32
            fn error() -> BoundsError {
48
32
                Self::error()
49
32
            }
Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds as jiff_core::bounds::Bounds>::error
<jiff::util::b::SpanYears as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
400
            fn error() -> BoundsError {
48
400
                Self::error()
49
400
            }
<jiff::util::b::SpanMonths as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
395
            fn error() -> BoundsError {
48
395
                Self::error()
49
395
            }
<jiff::util::b::SpanWeeks as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
370
            fn error() -> BoundsError {
48
370
                Self::error()
49
370
            }
<jiff::util::b::SpanDays as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
374
            fn error() -> BoundsError {
48
374
                Self::error()
49
374
            }
<jiff::util::b::SpanHours as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
362
            fn error() -> BoundsError {
48
362
                Self::error()
49
362
            }
<jiff::util::b::Day as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
5.95k
            fn error() -> BoundsError {
48
5.95k
                Self::error()
49
5.95k
            }
Unexecuted instantiation: <jiff::util::b::DayOfYear as jiff_core::bounds::Bounds>::error
<jiff::util::b::Hour as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
151
            fn error() -> BoundsError {
48
151
                Self::error()
49
151
            }
Unexecuted instantiation: <jiff::util::b::Hour12 as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::ISOWeek as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::ISOYear as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::Increment as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::Increment32 as jiff_core::bounds::Bounds>::error
<jiff::util::b::LeapSecond as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
10
            fn error() -> BoundsError {
48
10
                Self::error()
49
10
            }
Unexecuted instantiation: <jiff::util::b::Microsecond as jiff_core::bounds::Bounds>::error
Unexecuted instantiation: <jiff::util::b::Millisecond as jiff_core::bounds::Bounds>::error
<jiff::util::b::Minute as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
50
            fn error() -> BoundsError {
48
50
                Self::error()
49
50
            }
<jiff::util::b::Month as jiff_core::bounds::Bounds>::error
Line
Count
Source
47
879
            fn error() -> BoundsError {
48
879
                Self::error()
49
879
            }
50
        }
51
52
        #[allow(dead_code)]
53
        impl $name {
54
            pub(crate) const MIN: $ty = <$name as Bounds>::MIN;
55
            pub(crate) const MAX: $ty = <$name as Bounds>::MAX;
56
            const LEN: i128 = Self::MAX as i128 - Self::MIN as i128 + 1;
57
58
            #[cold]
59
9.86k
            pub(crate) const fn error() -> BoundsError {
60
9.86k
                BoundsError::$name(RawBoundsError::new())
61
9.86k
            }
Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::error
<jiff::util::b::SpanMinutes>::error
Line
Count
Source
59
338
            pub(crate) const fn error() -> BoundsError {
60
338
                BoundsError::$name(RawBoundsError::new())
61
338
            }
<jiff::util::b::SpanSeconds>::error
Line
Count
Source
59
386
            pub(crate) const fn error() -> BoundsError {
60
386
                BoundsError::$name(RawBoundsError::new())
61
386
            }
Unexecuted instantiation: <jiff::util::b::SpanMilliseconds>::error
Unexecuted instantiation: <jiff::util::b::SpanMicroseconds>::error
Unexecuted instantiation: <jiff::util::b::SpanMultiple>::error
Unexecuted instantiation: <jiff::util::b::YearCE>::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::SpanNanoseconds>::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::UnixEpochMilliseconds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds>::error
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds>::error
Unexecuted instantiation: <jiff::util::b::WeekNum>::error
Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::error
Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::error
Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::error
Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::error
<jiff::util::b::Year>::error
Line
Count
Source
59
90
            pub(crate) const fn error() -> BoundsError {
60
90
                BoundsError::$name(RawBoundsError::new())
61
90
            }
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::Nanosecond>::error
Unexecuted instantiation: <jiff::util::b::NthWeekday>::error
<jiff::util::b::OffsetHours>::error
Line
Count
Source
59
49
            pub(crate) const fn error() -> BoundsError {
60
49
                BoundsError::$name(RawBoundsError::new())
61
49
            }
<jiff::util::b::OffsetMinutes>::error
Line
Count
Source
59
17
            pub(crate) const fn error() -> BoundsError {
60
17
                BoundsError::$name(RawBoundsError::new())
61
17
            }
<jiff::util::b::OffsetSeconds>::error
Line
Count
Source
59
10
            pub(crate) const fn error() -> BoundsError {
60
10
                BoundsError::$name(RawBoundsError::new())
61
10
            }
Unexecuted instantiation: <jiff::util::b::OffsetTotalSeconds>::error
<jiff::util::b::Second>::error
Line
Count
Source
59
32
            pub(crate) const fn error() -> BoundsError {
60
32
                BoundsError::$name(RawBoundsError::new())
61
32
            }
<jiff::util::b::SpanYears>::error
Line
Count
Source
59
400
            pub(crate) const fn error() -> BoundsError {
60
400
                BoundsError::$name(RawBoundsError::new())
61
400
            }
<jiff::util::b::SpanMonths>::error
Line
Count
Source
59
395
            pub(crate) const fn error() -> BoundsError {
60
395
                BoundsError::$name(RawBoundsError::new())
61
395
            }
<jiff::util::b::SpanWeeks>::error
Line
Count
Source
59
370
            pub(crate) const fn error() -> BoundsError {
60
370
                BoundsError::$name(RawBoundsError::new())
61
370
            }
<jiff::util::b::SpanDays>::error
Line
Count
Source
59
374
            pub(crate) const fn error() -> BoundsError {
60
374
                BoundsError::$name(RawBoundsError::new())
61
374
            }
<jiff::util::b::SpanHours>::error
Line
Count
Source
59
362
            pub(crate) const fn error() -> BoundsError {
60
362
                BoundsError::$name(RawBoundsError::new())
61
362
            }
<jiff::util::b::Day>::error
Line
Count
Source
59
5.95k
            pub(crate) const fn error() -> BoundsError {
60
5.95k
                BoundsError::$name(RawBoundsError::new())
61
5.95k
            }
Unexecuted instantiation: <jiff::util::b::DayOfYear>::error
<jiff::util::b::Hour>::error
Line
Count
Source
59
151
            pub(crate) const fn error() -> BoundsError {
60
151
                BoundsError::$name(RawBoundsError::new())
61
151
            }
Unexecuted instantiation: <jiff::util::b::Hour12>::error
Unexecuted instantiation: <jiff::util::b::ISOWeek>::error
Unexecuted instantiation: <jiff::util::b::ISOYear>::error
Unexecuted instantiation: <jiff::util::b::Increment>::error
Unexecuted instantiation: <jiff::util::b::Increment32>::error
<jiff::util::b::LeapSecond>::error
Line
Count
Source
59
10
            pub(crate) const fn error() -> BoundsError {
60
10
                BoundsError::$name(RawBoundsError::new())
61
10
            }
Unexecuted instantiation: <jiff::util::b::Microsecond>::error
Unexecuted instantiation: <jiff::util::b::Millisecond>::error
<jiff::util::b::Minute>::error
Line
Count
Source
59
50
            pub(crate) const fn error() -> BoundsError {
60
50
                BoundsError::$name(RawBoundsError::new())
61
50
            }
<jiff::util::b::Month>::error
Line
Count
Source
59
879
            pub(crate) const fn error() -> BoundsError {
60
879
                BoundsError::$name(RawBoundsError::new())
61
879
            }
62
63
            #[cfg_attr(feature = "perf-inline", inline(always))]
64
84.1k
            pub(crate) fn check(
65
84.1k
                n: impl Into<i64>,
66
84.1k
            ) -> Result<$ty, BoundsError> {
67
84.1k
                <$name as Bounds>::check(n)
68
84.1k
            }
<jiff::util::b::SpanMinutes>::check::<i64>
Line
Count
Source
64
527
            pub(crate) fn check(
65
527
                n: impl Into<i64>,
66
527
            ) -> Result<$ty, BoundsError> {
67
527
                <$name as Bounds>::check(n)
68
527
            }
<jiff::util::b::SpanSeconds>::check::<i64>
Line
Count
Source
64
983
            pub(crate) fn check(
65
983
                n: impl Into<i64>,
66
983
            ) -> Result<$ty, BoundsError> {
67
983
                <$name as Bounds>::check(n)
68
983
            }
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check::<i64>
<jiff::util::b::SpanYears>::check::<i64>
Line
Count
Source
64
404
            pub(crate) fn check(
65
404
                n: impl Into<i64>,
66
404
            ) -> Result<$ty, BoundsError> {
67
404
                <$name as Bounds>::check(n)
68
404
            }
<jiff::util::b::SpanMonths>::check::<i64>
Line
Count
Source
64
444
            pub(crate) fn check(
65
444
                n: impl Into<i64>,
66
444
            ) -> Result<$ty, BoundsError> {
67
444
                <$name as Bounds>::check(n)
68
444
            }
<jiff::util::b::SpanWeeks>::check::<i64>
Line
Count
Source
64
424
            pub(crate) fn check(
65
424
                n: impl Into<i64>,
66
424
            ) -> Result<$ty, BoundsError> {
67
424
                <$name as Bounds>::check(n)
68
424
            }
<jiff::util::b::SpanDays>::check::<i64>
Line
Count
Source
64
513
            pub(crate) fn check(
65
513
                n: impl Into<i64>,
66
513
            ) -> Result<$ty, BoundsError> {
67
513
                <$name as Bounds>::check(n)
68
513
            }
<jiff::util::b::SpanHours>::check::<i64>
Line
Count
Source
64
498
            pub(crate) fn check(
65
498
                n: impl Into<i64>,
66
498
            ) -> Result<$ty, BoundsError> {
67
498
                <$name as Bounds>::check(n)
68
498
            }
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::YearCE>::check::<i16>
Unexecuted instantiation: <jiff::util::b::YearBCE>::check::<i16>
Unexecuted instantiation: <jiff::util::b::YearTwoDigit>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanNanoseconds>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::check::<u32>
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check::<i64>
Unexecuted instantiation: <jiff::util::b::WeekNum>::check::<i64>
Unexecuted instantiation: <jiff::util::b::Year>::check::<i16>
<jiff::util::b::Year>::check::<i64>
Line
Count
Source
64
47.6k
            pub(crate) fn check(
65
47.6k
                n: impl Into<i64>,
66
47.6k
            ) -> Result<$ty, BoundsError> {
67
47.6k
                <$name as Bounds>::check(n)
68
47.6k
            }
Unexecuted instantiation: <jiff::util::b::Century>::check::<i64>
Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::check::<i64>
<jiff::util::b::Second>::check::<i64>
Line
Count
Source
64
1.54k
            pub(crate) fn check(
65
1.54k
                n: impl Into<i64>,
66
1.54k
            ) -> Result<$ty, BoundsError> {
67
1.54k
                <$name as Bounds>::check(n)
68
1.54k
            }
Unexecuted instantiation: <jiff::util::b::SpanYears>::check::<i64>
<jiff::util::b::SpanMonths>::check::<i32>
Line
Count
Source
64
359
            pub(crate) fn check(
65
359
                n: impl Into<i64>,
66
359
            ) -> Result<$ty, BoundsError> {
67
359
                <$name as Bounds>::check(n)
68
359
            }
Unexecuted instantiation: <jiff::util::b::SpanMonths>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanWeeks>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanDays>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanHours>::check::<i64>
Unexecuted instantiation: <jiff::util::b::Day>::check::<i8>
<jiff::util::b::Day>::check::<i64>
Line
Count
Source
64
10.3k
            pub(crate) fn check(
65
10.3k
                n: impl Into<i64>,
66
10.3k
            ) -> Result<$ty, BoundsError> {
67
10.3k
                <$name as Bounds>::check(n)
68
10.3k
            }
Unexecuted instantiation: <jiff::util::b::DayOfYear>::check::<i64>
<jiff::util::b::Hour>::check::<i8>
Line
Count
Source
64
2.52k
            pub(crate) fn check(
65
2.52k
                n: impl Into<i64>,
66
2.52k
            ) -> Result<$ty, BoundsError> {
67
2.52k
                <$name as Bounds>::check(n)
68
2.52k
            }
<jiff::util::b::Hour>::check::<i64>
Line
Count
Source
64
2.65k
            pub(crate) fn check(
65
2.65k
                n: impl Into<i64>,
66
2.65k
            ) -> Result<$ty, BoundsError> {
67
2.65k
                <$name as Bounds>::check(n)
68
2.65k
            }
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::Increment32>::check::<i64>
<jiff::util::b::Minute>::check::<i64>
Line
Count
Source
64
1.90k
            pub(crate) fn check(
65
1.90k
                n: impl Into<i64>,
66
1.90k
            ) -> Result<$ty, BoundsError> {
67
1.90k
                <$name as Bounds>::check(n)
68
1.90k
            }
Unexecuted instantiation: <jiff::util::b::Month>::check::<i8>
<jiff::util::b::Month>::check::<i64>
Line
Count
Source
64
11.8k
            pub(crate) fn check(
65
11.8k
                n: impl Into<i64>,
66
11.8k
            ) -> Result<$ty, BoundsError> {
67
11.8k
                <$name as Bounds>::check(n)
68
11.8k
            }
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::SignedSubsecNanosecond>::check::<_>
Unexecuted instantiation: <jiff::util::b::UnixEpochMilliseconds>::check::<_>
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds>::check::<_>
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds>::check::<_>
Unexecuted instantiation: <jiff::util::b::WeekdayMondayZero>::check::<_>
Unexecuted instantiation: <jiff::util::b::WeekdayMondayOne>::check::<_>
Unexecuted instantiation: <jiff::util::b::WeekdaySundayZero>::check::<_>
Unexecuted instantiation: <jiff::util::b::WeekdaySundayOne>::check::<_>
Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::check::<_>
Unexecuted instantiation: <jiff::util::b::Nanosecond>::check::<_>
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::OffsetTotalSeconds>::check::<_>
Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::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::SpanMinutes>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanSeconds>::check::<i64>
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check::<i64>
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::SpanDays>::check::<i64>
Unexecuted instantiation: <jiff::util::b::SpanHours>::check::<i64>
<jiff::util::b::SpanMinutes>::check::<i64>
Line
Count
Source
64
225
            pub(crate) fn check(
65
225
                n: impl Into<i64>,
66
225
            ) -> Result<$ty, BoundsError> {
67
225
                <$name as Bounds>::check(n)
68
225
            }
<jiff::util::b::SpanSeconds>::check::<i64>
Line
Count
Source
64
337
            pub(crate) fn check(
65
337
                n: impl Into<i64>,
66
337
            ) -> Result<$ty, BoundsError> {
67
337
                <$name as Bounds>::check(n)
68
337
            }
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::check::<i64>
<jiff::util::b::SpanYears>::check::<i64>
Line
Count
Source
64
193
            pub(crate) fn check(
65
193
                n: impl Into<i64>,
66
193
            ) -> Result<$ty, BoundsError> {
67
193
                <$name as Bounds>::check(n)
68
193
            }
<jiff::util::b::SpanMonths>::check::<i64>
Line
Count
Source
64
189
            pub(crate) fn check(
65
189
                n: impl Into<i64>,
66
189
            ) -> Result<$ty, BoundsError> {
67
189
                <$name as Bounds>::check(n)
68
189
            }
<jiff::util::b::SpanWeeks>::check::<i64>
Line
Count
Source
64
196
            pub(crate) fn check(
65
196
                n: impl Into<i64>,
66
196
            ) -> Result<$ty, BoundsError> {
67
196
                <$name as Bounds>::check(n)
68
196
            }
<jiff::util::b::SpanDays>::check::<i64>
Line
Count
Source
64
203
            pub(crate) fn check(
65
203
                n: impl Into<i64>,
66
203
            ) -> Result<$ty, BoundsError> {
67
203
                <$name as Bounds>::check(n)
68
203
            }
<jiff::util::b::SpanHours>::check::<i64>
Line
Count
Source
64
208
            pub(crate) fn check(
65
208
                n: impl Into<i64>,
66
208
            ) -> Result<$ty, BoundsError> {
67
208
                <$name as Bounds>::check(n)
68
208
            }
69
70
            #[cfg_attr(feature = "perf-inline", inline(always))]
71
36
            pub(crate) const fn checkc(n: i64) -> Result<$ty, BoundsError> {
72
36
                match const_check::$ty(n) {
73
36
                    Ok(n) => Ok(n),
74
0
                    Err(err) => Err(BoundsError::$name(err)),
75
                }
76
36
            }
<jiff::util::b::OffsetHours>::checkc
Line
Count
Source
71
36
            pub(crate) const fn checkc(n: i64) -> Result<$ty, BoundsError> {
72
36
                match const_check::$ty(n) {
73
36
                    Ok(n) => Ok(n),
74
0
                    Err(err) => Err(BoundsError::$name(err)),
75
                }
76
36
            }
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::YearCE>::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::SpanNanoseconds>::checkc
Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checkc
Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checkc
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checkc
Unexecuted instantiation: <jiff::util::b::UnixEpochMilliseconds>::checkc
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds>::checkc
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds>::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::Century>::checkc
Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checkc
Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checkc
Unexecuted instantiation: <jiff::util::b::Nanosecond>::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::OffsetTotalSeconds>::checkc
Unexecuted instantiation: <jiff::util::b::Second>::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::Day>::checkc
Unexecuted instantiation: <jiff::util::b::DayOfYear>::checkc
Unexecuted instantiation: <jiff::util::b::Hour>::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::Minute>::checkc
Unexecuted instantiation: <jiff::util::b::Month>::checkc
77
78
            #[cfg_attr(feature = "perf-inline", inline(always))]
79
666
            pub(crate) fn checked_add(
80
666
                n1: $ty,
81
666
                n2: $ty,
82
666
            ) -> Result<$ty, BoundsError> {
83
666
                <$name as Bounds>::checked_add(n1, n2)
84
666
            }
<jiff::util::b::Year>::checked_add
Line
Count
Source
79
666
            pub(crate) fn checked_add(
80
666
                n1: $ty,
81
666
                n2: $ty,
82
666
            ) -> Result<$ty, BoundsError> {
83
666
                <$name as Bounds>::checked_add(n1, n2)
84
666
            }
Unexecuted instantiation: <jiff::util::b::SpanMonths>::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::YearCE>::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::SpanNanoseconds>::checked_add
Unexecuted instantiation: <jiff::util::b::SubsecNanosecond>::checked_add
Unexecuted instantiation: <jiff::util::b::SignedSubsecNanosecond>::checked_add
Unexecuted instantiation: <jiff::util::b::UnixEpochDays>::checked_add
Unexecuted instantiation: <jiff::util::b::UnixEpochMilliseconds>::checked_add
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds>::checked_add
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds>::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::Century>::checked_add
Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checked_add
Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checked_add
Unexecuted instantiation: <jiff::util::b::Nanosecond>::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::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::Day>::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
85
86
            #[cfg_attr(feature = "perf-inline", inline(always))]
87
0
            pub(crate) fn checked_mul(
88
0
                n1: $ty,
89
0
                n2: $ty,
90
0
            ) -> Result<$ty, BoundsError> {
91
0
                <$name as Bounds>::checked_mul(n1, n2)
92
0
            }
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::SpanMultiple>::checked_mul
Unexecuted instantiation: <jiff::util::b::YearCE>::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::SpanNanoseconds>::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::UnixEpochMilliseconds>::checked_mul
Unexecuted instantiation: <jiff::util::b::UnixEpochMicroseconds>::checked_mul
Unexecuted instantiation: <jiff::util::b::UnixEpochSeconds>::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::Century>::checked_mul
Unexecuted instantiation: <jiff::util::b::CivilDayNanosecond>::checked_mul
Unexecuted instantiation: <jiff::util::b::CivilDaySecond>::checked_mul
Unexecuted instantiation: <jiff::util::b::Nanosecond>::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::Second>::checked_mul
Unexecuted instantiation: <jiff::util::b::SignedDurationSeconds>::checked_mul
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::Day>::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
93
94
            #[cfg(test)]
95
            pub(crate) fn arbitrary(g: &mut quickcheck::Gen) -> $ty {
96
                use quickcheck::Arbitrary;
97
98
                let mut n: $ty = <$ty>::arbitrary(g);
99
                n = n.wrapping_rem_euclid(Self::LEN as $ty);
100
                n += Self::MIN;
101
                n
102
            }
103
        }
104
    };
105
    // A shortcut for defining a boundary type in `jiff` that is just a mirror
106
    // of a boundary type defined in `jiff-core`. We do this instead of using
107
    // the boundary type from `jiff-core` directly because we can't have a
108
    // `From` impl on a `jiff-core` error type for `jiff::Error`. (Because
109
    // that would make `jiff-core` a public dependency of `jiff`. Which means
110
    // any semver incompatible release of `jiff-core` would require a semver
111
    // incompatible release of `jiff`. Since `jiff-core` evolves more quickly
112
    // than `jiff`, this would be bad juju.)
113
    ($name:ident, $ty:ident $(,)?) => {
114
        define_one_boundary_type!(
115
            $name,
116
            $ty,
117
            jcore::bounds::$name::WHAT,
118
            jcore::bounds::$name::MIN,
119
            jcore::bounds::$name::MAX,
120
        );
121
    };
122
}
123
124
/// This macro writes out the boiler plate to define a boundary type.
125
///
126
/// Specifically, it implements the `Bounds` trait and provides a few
127
/// concrete methods. The concrete methods are mostly wrappers around
128
/// the generic trait methods. They are provided so that callers don't
129
/// have to import the `Bounds` trait to use them.
130
macro_rules! define_bounds {
131
    ($((
132
        $name:ident,
133
        $ty:ident
134
        $($tt:tt)*
135
    )),* $(,)?) => {
136
        $(
137
            define_one_boundary_type!($name, $ty $($tt)*);
138
        )*
139
140
        /// An error that indicates a value is out of its intended range.
141
        #[derive(Clone, Debug)]
142
        #[cfg_attr(feature = "defmt", derive(defmt::Format))]
143
        pub(crate) enum BoundsError {
144
            $($name(RawBoundsError<$name>),)*
145
        }
146
147
        impl core::fmt::Display for BoundsError {
148
0
            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
149
0
                match *self {
150
0
                    $(BoundsError::$name(ref err) => err.fmt(f),)*
151
                }
152
0
            }
153
        }
154
    }
155
}
156
157
// This is where we define all of Jiff's ranges.
158
//
159
// Well, that's not quite true. Many of them are actually defined in
160
// `jiff-core`. For those, we still have an entry here that still produces
161
// a boundary type, but it reuses the minimum and maximum values from
162
// `jiff-core`. This is so `jiff` completely owns its own boundary types
163
// (to avoid a public dep on `jiff-core`) while simultaneously preserving a
164
// single point of truth for every range type.
165
define_bounds! {
166
    (Century, i8, "century", 0, 99),
167
    (CivilDayNanosecond, i64),
168
    (CivilDaySecond, i32),
169
    (Day, i8),
170
    (DayOfYear, i16),
171
    (Hour, i8),
172
    (Hour12, i8, "hour (12 hour clock)", 1, 12),
173
    (ISOWeek, i8),
174
    (ISOYear, i16),
175
    // This matches Temporal's range.
176
    // See: https://github.com/tc39/proposal-temporal/issues/2458#issuecomment-1380742911
177
    (Increment, i64, "rounding increment", 1, 1_000_000_000),
178
    (Increment32, i32, "rounding increment", 1, 1_000_000_000),
179
    // This is only used in parsing. A value of `60` gets clamped to `59`.
180
    (LeapSecond, i8, "second", 0, 60),
181
    (Microsecond, i16),
182
    (Millisecond, i16),
183
    (Minute, i8),
184
    (Month, i8),
185
    (Nanosecond, i16),
186
    (NthWeekday, i32),
187
    (OffsetHours, i8),
188
    (OffsetMinutes, i8),
189
    (OffsetSeconds, i8),
190
    (OffsetTotalSeconds, i32),
191
    (Second, i8),
192
    (SignedDurationSeconds, i64, "signed duration seconds", i64::MIN, i64::MAX),
193
    (SpanYears, i16, "years", -Self::MAX, (Year::LEN - 1) as i16),
194
    (SpanMonths, i32, "months", -Self::MAX, SpanYears::MAX as i32 * 12),
195
    (SpanWeeks, i32, "weeks", -Self::MAX, SpanDays::MAX / c::DAYS_PER_CIVIL_WEEK_32),
196
    (SpanDays, i32, "days", -Self::MAX, SpanHours::MAX / c::HOURS_PER_CIVIL_DAY_32),
197
    (SpanHours, i32, "hours", -Self::MAX, (SpanMinutes::MAX / c::MINS_PER_HOUR) as i32),
198
    (SpanMinutes, i64, "minutes", -Self::MAX, SpanSeconds::MAX / c::SECS_PER_MIN),
199
    (
200
        SpanSeconds,
201
        i64,
202
        "seconds",
203
        bounds::DeltaSeconds::MIN,
204
        bounds::DeltaSeconds::MAX,
205
    ),
206
    (
207
        SpanMilliseconds,
208
        i64,
209
        "milliseconds",
210
        -Self::MAX,
211
        SpanSeconds::MAX * c::MILLIS_PER_SEC,
212
    ),
213
    (
214
        SpanMicroseconds,
215
        i64,
216
        "microseconds",
217
        -Self::MAX,
218
        SpanMilliseconds::MAX * c::MICROS_PER_MILLI,
219
    ),
220
    (SpanMultiple, i64, "span multiple", i64::MIN  + 1, i64::MAX),
221
    // A range of the allowed number of nanoseconds.
222
    //
223
    // For this, we cannot cover the full span of supported time instants since
224
    // `UnixSeconds::MAX * NANOSECONDS_PER_SECOND` cannot fit into 64-bits. We
225
    // could use a `i128`, but it doesn't seem worth bloating up `Span`.
226
    //
227
    // Also note that our min is equal to -max, so that the total number of
228
    // values in this range is one less than the number of distinct `i64`
229
    // values. We do that so that the absolute value is always defined.
230
    (SpanNanoseconds, i64, "nanoseconds", i64::MIN + 1, i64::MAX),
231
    (SubsecNanosecond, i32),
232
    (SignedSubsecNanosecond, i32),
233
    (UnixEpochDays, i32),
234
    (
235
        UnixEpochMilliseconds,
236
        i64,
237
        "Unix timestamp milliseconds",
238
        UnixEpochSeconds::MIN * c::MILLIS_PER_SEC,
239
        UnixEpochSeconds::MAX * c::MILLIS_PER_SEC,
240
    ),
241
    (
242
        UnixEpochMicroseconds,
243
        i64,
244
        "Unix timestamp microseconds",
245
        UnixEpochMilliseconds::MIN * c::MICROS_PER_MILLI,
246
        UnixEpochMilliseconds::MAX * c::MICROS_PER_MILLI,
247
    ),
248
    (UnixEpochSeconds, i64),
249
    (WeekNum, i8, "week-number", 0, 53),
250
    (WeekdayMondayZero, i8),
251
    (WeekdayMondayOne, i8),
252
    (WeekdaySundayZero, i8),
253
    (WeekdaySundayOne, i8),
254
    // The range of years supported by Jiff.
255
    //
256
    // This is ultimately where some of the other ranges (like `UnixSeconds`)
257
    // were determined from. That is, the range of years is the primary point
258
    // at which the space of supported time instants is derived from. If one
259
    // wanted to expand this range, you'd need to change it here and then
260
    // compute the corresponding min/max values for `UnixSeconds`. (Among other
261
    // things... Increasing the supported Jiff range is far more complicated
262
    // than just changing some ranges here.)
263
    (Year, i16),
264
    (YearCE, i16),
265
    (YearBCE, i16),
266
    (YearTwoDigit, i16, "year (2 digits)", 0, 99),
267
    (
268
        ZonedDayNanoseconds,
269
        i64,
270
        "nanoseconds (in one zoned datetime day)",
271
        ZonedDaySeconds::MIN as i64 * c::NANOS_PER_SEC,
272
        ZonedDaySeconds::MAX as i64 * c::NANOS_PER_SEC,
273
    ),
274
    // The number of seconds permitted in a single day.
275
    //
276
    // This is mostly just a "sensible" cap on what is possible. We allow one
277
    // day to span up to 7 civil days.
278
    //
279
    // It must also be at least 1 second long.
280
    (
281
        ZonedDaySeconds,
282
        i32,
283
        "seconds (in one zoned datetime day)",
284
        1,
285
        7 * c::SECS_PER_CIVIL_DAY_32,
286
    ),
287
}
288
289
impl From<BoundsError> for Error {
290
9.86k
    fn from(err: BoundsError) -> Error {
291
9.86k
        Error::bounds(err)
292
9.86k
    }
293
}
294
295
impl crate::error::IntoError for BoundsError {
296
1.47k
    fn into_error(self) -> Error {
297
1.47k
        self.into()
298
1.47k
    }
299
}
300
301
/// Like `BoundsError`, but maintained manually.
302
///
303
/// This is useful for range errors outside of the framework above.
304
#[derive(Clone, Debug)]
305
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
306
pub(crate) enum SpecialBoundsError {
307
    SignedDurationFloatOutOfRangeF32,
308
    SignedDurationFloatOutOfRangeF64,
309
    SignedToUnsignedDuration,
310
}
311
312
impl core::fmt::Display for SpecialBoundsError {
313
0
    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
314
        use self::SpecialBoundsError::*;
315
316
0
        match *self {
317
0
            SignedToUnsignedDuration => f.write_str(
318
0
                "negative signed durations cannot be converted \
319
0
                 to an unsigned duration",
320
            ),
321
            SignedDurationFloatOutOfRangeF32 => {
322
0
                write!(
323
0
                    f,
324
                    "parameter 'floating point seconds' is not in \
325
                     the required range of {min}..={max}",
326
                    min = i64::MIN as f32,
327
                    max = i64::MAX as f32,
328
                )
329
            }
330
            SignedDurationFloatOutOfRangeF64 => {
331
0
                write!(
332
0
                    f,
333
                    "parameter 'floating point seconds' is not in \
334
                     the required range of {min}..={max}",
335
                    min = i64::MIN as f64,
336
                    max = i64::MAX as f64,
337
                )
338
            }
339
        }
340
0
    }
341
}
342
343
impl From<SpecialBoundsError> for Error {
344
0
    fn from(err: SpecialBoundsError) -> Error {
345
0
        Error::special_bounds(err)
346
0
    }
347
}
348
349
impl crate::error::IntoError for SpecialBoundsError {
350
0
    fn into_error(self) -> Error {
351
0
        self.into()
352
0
    }
353
}
354
355
#[cfg(test)]
356
mod tests {
357
    use alloc::string::ToString;
358
359
    use super::*;
360
361
    #[test]
362
    fn size_of_bounds_error() {
363
        // It's okay if this grows, but I wrote this test initially
364
        // to confirm that a `BoundsError` is very small. (Since it's
365
        // just a bunch of variants of ZSTs.)
366
        assert_eq!(1, core::mem::size_of::<BoundsError>());
367
    }
368
369
    #[test]
370
    fn basic_error_functionality() {
371
        let err = Year::check(10_000).unwrap_err();
372
        assert_eq!(
373
            err.to_string(),
374
            "parameter 'year' is not in the required range of -9999..=9999",
375
        );
376
    }
377
}