pub(crate) enum Duration {
Span(Span),
Signed(SignedDuration),
Unsigned(Duration),
}
Expand description
An internal type for abstracting over different duration types.
Variants§
Implementations§
Source§impl Duration
impl Duration
Sourcepub(crate) fn to_signed(self) -> Result<SDuration, Error>
pub(crate) fn to_signed(self) -> Result<SDuration, Error>
Convert this to a signed duration.
This returns an error only in the case where this is an unsigned
duration with a number of whole seconds that exceeds |i64::MIN|
.
Sourcepub(crate) fn checked_neg(self) -> Result<Duration, Error>
pub(crate) fn checked_neg(self) -> Result<Duration, Error>
Negates this duration.
When the duration is a span, this can never fail because a span defines its min and max values such that negation is always possible.
When the duration is signed, then this attempts to return a signed
duration and only falling back to an unsigned duration when the number
of seconds corresponds to i64::MIN
.
When the duration is unsigned, then this fails when the whole seconds
exceed the absolute value of i64::MIN
. Otherwise, a signed duration
is returned.
The failures for large unsigned durations here are okay because the point at which absolute durations overflow on negation, they would also cause overflow when adding or subtracting to any valid datetime value for any datetime type in this crate. So while the error message may be different, the actual end result is the same (failure).
TODO: Write unit tests for this.
Sourcepub(crate) fn is_negative(&self) -> bool
pub(crate) fn is_negative(&self) -> bool
Returns true if and only if this duration is negative.