Struct SignedDuration
struct SignedDuration { ... }
A signed duration of time represented as a 96-bit integer of nanoseconds.
Each duration is made up of a 64-bit integer of whole seconds and a
32-bit integer of fractional nanoseconds less than 1 whole second. Unlike
std::time::Duration, this duration is signed. The sign applies
to the entire duration. That is, either both the seconds and the
fractional nanoseconds are negative or neither are. Stated differently,
it is guaranteed that the signs of SignedDuration::as_secs and
SignedDuration::subsec_nanos are always the same, or one component is
zero. (For example, -1 seconds and 0 nanoseconds, or 0 seconds and
-1 nanoseconds.)
Parsing and printing
Like the Span type, the SignedDuration type
provides convenient trait implementations of std::str::FromStr and
[std::fmt::Display]:
use SignedDuration;
let duration: SignedDuration = "PT2h30m".parse?;
assert_eq!;
// Or use the "friendly" format by invoking the alternate:
assert_eq!;
// Parsing automatically supports both the ISO 8601 and "friendly" formats:
let duration: SignedDuration = "2h 30m".parse?;
assert_eq!;
let duration: SignedDuration = "2 hours, 30 minutes".parse?;
assert_eq!;
# Ok::
Unlike the Span type, though, only uniform units are supported. This
means that ISO 8601 durations with non-zero units of days or greater cannot
be parsed directly into a SignedDuration:
use SignedDuration;
assert_eq!;
# Ok::
To parse such durations, one should first parse them into a Span and
then convert them to a SignedDuration by providing a relative date:
use ;
let span: Span = "P1d".parse?;
let relative = date.in_tz?;
let duration = span.to_duration?;
// This example also motivates *why* a relative date
// is required. Not all days are the same length!
assert_eq!;
# Ok::
The format supported is a variation (nearly a subset) of the duration format specified in ISO 8601 and a Jiff-specific "friendly" format. Here are more examples:
use SignedDuration;
let durations = ;
for in durations
# Ok::
For more details, see the fmt::temporal and
fmt::friendly modules.
API design
A SignedDuration is, as much as is possible, a replica of the
std::time::Duration API. While there are probably some quirks in the API
of std::time::Duration that could have been fixed here, it is probably
more important that it behave "exactly like a std::time::Duration but
with a sign." That is, this type mirrors the parallels between signed and
unsigned integer types.
While the goal was to match the std::time::Duration API as much as
possible, there are some differences worth highlighting:
- As stated, a
SignedDurationhas a sign. Therefore, it usesi64andi32instead ofu64andu32to represent its 96-bit integer. - Because it's signed, the range of possible values is different. For
example, a
SignedDuration::MAXhas a whole number of seconds equivalent toi64::MAX, which is less thanu64::MAX. - There are some additional APIs that don't make sense on an unsigned
duration, like
SignedDuration::absandSignedDuration::checked_neg. - A
SignedDuration::system_untilroutine is provided as a replacement forstd::time::SystemTime::duration_since, but with signed durations. - Constructors and getters for units of hours and minutes are provided, where as these routines are unstable in the standard library.
- Unlike the standard library, this type implements the
std::fmt::Displayandstd::str::FromStrtraits via the ISO 8601 duration format, just like theSpantype does. Also likeSpan, the ISO 8601 duration format is used to implement the serdeSerializeandDeserializetraits when theserdecrate feature is enabled. - The
std::fmt::Debugtrait implementation is a bit different. If you have a problem with it, please file an issue. - At present, there is no
SignedDuration::abs_diffsince there are some API design questions. If you want it, please file an issue.
When should I use SignedDuration versus Span?
Jiff's primary duration type is Span. The key differences between it and
SignedDuration are:
- A
Spankeeps track of each individual unit separately. That is, even though1 hour 60 minutesand2 hoursare equivalent durations of time, representing each as aSpancorresponds to two distinct values in memory. And serializing them to the ISO 8601 duration format will also preserve the units, for example,PT1h60mandPT2h. - A
Spansupports non-uniform units like days, weeks, months and years. Since not all days, weeks, months and years have the same length, they cannot be represented by aSignedDuration. In some cases, it may be appropriate, for example, to assume that all days are 24 hours long. But since Jiff sometimes assumes all days are 24 hours (for civil time) and sometimes doesn't (like forZonedwhen respecting time zones), it would be inappropriate to bake one of those assumptions into aSignedDuration. - A
SignedDurationis a much smaller type than aSpan. Specifically, it's a 96-bit integer. In contrast, aSpanis much larger since it needs to track each individual unit separately.
Those differences in turn motivate some approximate reasoning for when to
use Span and when to use SignedDuration:
- If you don't care about keeping track of individual units separately or
don't need the sophisticated rounding options available on a
Span, it might be simpler and faster to use aSignedDuration. - If you specifically need performance on arithmetic operations involving
datetimes and durations, even if it's not as convenient or correct, then it
might make sense to use a
SignedDuration. - If you need to perform arithmetic using a
std::time::Durationand otherwise don't need the functionality of aSpan, it might make sense to first convert thestd::time::Durationto aSignedDuration, and then use one of the corresponding operations defined forSignedDurationon the datetime types. (They all support it.)
In general, a Span provides more functionality and is overall more
flexible. A Span can also deserialize all forms of ISO 8601 durations
(as long as they're within Jiff's limits), including durations with units
of years, months, weeks and days. A SignedDuration, by contrast, only
supports units up to and including hours.
Integration with datetime types
All datetime types that support arithmetic using Span also
support arithmetic using SignedDuration (and std::time::Duration).
For example, here's how to add an absolute duration to a [Timestamp]:
use ;
let ts1 = from_second?;
assert_eq!;
let duration = new;
// Timestamp::checked_add is polymorphic! It can accept a
// span or a duration.
let ts2 = ts1.checked_add?;
assert_eq!;
# Ok::
The same API pattern works with Zoned, DateTime, Date and
Time.
Interaction with daylight saving time and time zone transitions
A SignedDuration always corresponds to a specific number of nanoseconds.
Since a Zoned is always a precise instant in time, adding a SignedDuration
to a Zoned always behaves by adding the nanoseconds from the duration to
the timestamp inside of Zoned. Consider 2024-03-10 in US/Eastern.
At 02:00:00, daylight saving time came into effect, switching the UTC
offset for the region from -05 to -04. This has the effect of skipping
an hour on the clocks:
use ;
let zdt = date.at.in_tz?;
assert_eq!;
// The same would apply if you used a `Span`:
assert_eq!;
# Ok::
Where time zones might have a more interesting effect is in the definition
of the "day" itself. If, for example, you encode the notion that a day is
always 24 hours into your arithmetic, you might get unexpected results.
For example, let's say you want to find the datetime precisely one week
after 2024-03-08T17:00 in the US/Eastern time zone. You might be
tempted to just ask for the time that is 7 * 24 hours later:
use ;
let zdt = date.at.in_tz?;
assert_eq!;
# Ok::
Notice that you get 18:00 and not 17:00! That's because, as shown
in the previous example, 2024-03-10 was only 23 hours long. That in turn
implies that the week starting from 2024-03-08 is only 7 * 24 - 1 hours
long. This can be tricky to get correct with absolute durations like
SignedDuration, but a Span will handle this for you automatically:
use ;
let zdt = date.at.in_tz?;
assert_eq!;
# Ok::
A Span achieves this by keeping track of individual units. Unlike a
SignedDuration, it is not just a simple count of nanoseconds. It is a
"bag" of individual units, and the arithmetic operations defined on a
Span for Zoned know how to interpret "day" in a particular time zone
at a particular instant in time.
With that said, the above does not mean that using a SignedDuration is
always wrong. For example, if you're dealing with units of hours or lower,
then all such units are uniform and so you'll always get the same results
as with a Span. And using a SignedDuration can sometimes be simpler
or faster.
Implementations
impl SignedDuration
const fn new(secs: i64, nanos: i32) -> SignedDurationCreates a new
SignedDurationfrom the given number of whole seconds and additional nanoseconds.If the absolute value of the nanoseconds is greater than or equal to 1 second, then the excess balances into the number of whole seconds.
Panics
When the absolute value of the nanoseconds is greater than or equal to 1 second and the excess that carries over to the number of whole seconds overflows
i64.This never panics when
nanosis less than1_000_000_000.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!; let duration = new; assert_eq!; assert_eq!; let duration = new; assert_eq!; assert_eq!;const fn from_secs(secs: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of whole seconds.Example
use SignedDuration; let duration = from_secs; assert_eq!; assert_eq!;const fn from_millis(millis: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of whole milliseconds.Note that since this accepts an
i64, this method cannot be used to construct the full range of possible signed duration values. In particular,SignedDuration::as_millisreturns ani128, and this may be a value that would otherwise overflow ani64.Example
use SignedDuration; let duration = from_millis; assert_eq!; assert_eq!; let duration = from_millis; assert_eq!; assert_eq!;const fn from_micros(micros: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of whole microseconds.Note that since this accepts an
i64, this method cannot be used to construct the full range of possible signed duration values. In particular,SignedDuration::as_microsreturns ani128, and this may be a value that would otherwise overflow ani64.Example
use SignedDuration; let duration = from_micros; assert_eq!; assert_eq!; let duration = from_micros; assert_eq!; assert_eq!;const fn from_nanos(nanos: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of whole nanoseconds.Note that since this accepts an
i64, this method cannot be used to construct the full range of possible signed duration values. In particular,SignedDuration::as_nanosreturns ani128, which may be a value that would otherwise overflow ani64.Example
use SignedDuration; let duration = from_nanos; assert_eq!; assert_eq!; let duration = from_nanos; assert_eq!; assert_eq!;const fn from_hours(hours: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of hours. Every hour is exactly3,600seconds.Panics
Panics if the number of hours, after being converted to nanoseconds, overflows the minimum or maximum
SignedDurationvalues.Example
use SignedDuration; let duration = from_hours; assert_eq!; assert_eq!; let duration = from_hours; assert_eq!; assert_eq!;const fn from_mins(minutes: i64) -> SignedDurationCreates a new
SignedDurationfrom the given number of minutes. Every minute is exactly60seconds.Panics
Panics if the number of minutes, after being converted to nanoseconds, overflows the minimum or maximum
SignedDurationvalues.Example
use SignedDuration; let duration = from_mins; assert_eq!; assert_eq!; let duration = from_mins; assert_eq!; assert_eq!;const fn is_zero(self: &Self) -> boolReturns true if this duration spans no time.
Example
use SignedDuration; assert!; assert!; assert!;const fn as_secs(self: &Self) -> i64Returns the number of whole seconds in this duration.
The value returned is negative when the duration is negative.
This does not include any fractional component corresponding to units less than a second. To access those, use one of the
subsecmethods such asSignedDuration::subsec_nanos.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn subsec_millis(self: &Self) -> i32Returns the fractional part of this duration in whole milliseconds.
The value returned is negative when the duration is negative. It is guaranteed that the range of the value returned is in the inclusive range
-999..=999.To get the length of the total duration represented in milliseconds, use
SignedDuration::as_millis.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn subsec_micros(self: &Self) -> i32Returns the fractional part of this duration in whole microseconds.
The value returned is negative when the duration is negative. It is guaranteed that the range of the value returned is in the inclusive range
-999_999..=999_999.To get the length of the total duration represented in microseconds, use
SignedDuration::as_micros.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn subsec_nanos(self: &Self) -> i32Returns the fractional part of this duration in whole nanoseconds.
The value returned is negative when the duration is negative. It is guaranteed that the range of the value returned is in the inclusive range
-999_999_999..=999_999_999.To get the length of the total duration represented in nanoseconds, use
SignedDuration::as_nanos.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn as_millis(self: &Self) -> i128Returns the total duration in units of whole milliseconds.
The value returned is negative when the duration is negative.
To get only the fractional component of this duration in units of whole milliseconds, use
SignedDuration::subsec_millis.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn as_micros(self: &Self) -> i128Returns the total duration in units of whole microseconds.
The value returned is negative when the duration is negative.
To get only the fractional component of this duration in units of whole microseconds, use
SignedDuration::subsec_micros.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn as_nanos(self: &Self) -> i128Returns the total duration in units of whole nanoseconds.
The value returned is negative when the duration is negative.
To get only the fractional component of this duration in units of whole nanoseconds, use
SignedDuration::subsec_nanos.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn checked_add(self: Self, rhs: SignedDuration) -> Option<SignedDuration>Add two signed durations together. If overflow occurs, then
Noneis returned.Example
use SignedDuration; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = MAX; let duration2 = new; assert_eq!;const fn saturating_add(self: Self, rhs: SignedDuration) -> SignedDurationAdd two signed durations together. If overflow occurs, then arithmetic saturates.
Example
use SignedDuration; let duration1 = MAX; let duration2 = new; assert_eq!; let duration1 = MIN; let duration2 = new; assert_eq!;const fn checked_sub(self: Self, rhs: SignedDuration) -> Option<SignedDuration>Subtract one signed duration from another. If overflow occurs, then
Noneis returned.Example
use SignedDuration; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = MIN; let duration2 = new; assert_eq!;const fn saturating_sub(self: Self, rhs: SignedDuration) -> SignedDurationAdd two signed durations together. If overflow occurs, then arithmetic saturates.
Example
use SignedDuration; let duration1 = MAX; let duration2 = new; assert_eq!; let duration1 = MIN; let duration2 = new; assert_eq!;const fn checked_mul(self: Self, rhs: i32) -> Option<SignedDuration>Multiply this signed duration by an integer. If the multiplication overflows, then
Noneis returned.Example
use SignedDuration; let duration = new; assert_eq!;const fn saturating_mul(self: Self, rhs: i32) -> SignedDurationMultiply this signed duration by an integer. If the multiplication overflows, then the result saturates to either the minimum or maximum duration depending on the sign of the product.
Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!; let duration = new; assert_eq!; assert_eq!;const fn checked_div(self: Self, rhs: i32) -> Option<SignedDuration>Divide this duration by an integer. If the division overflows, then
Noneis returned.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!; let duration = new; assert_eq!; assert_eq!;fn as_secs_f64(self: &Self) -> f64Returns the number of seconds, with a possible fractional nanosecond component, represented by this signed duration as a 64-bit float.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;fn as_secs_f32(self: &Self) -> f32Returns the number of seconds, with a possible fractional nanosecond component, represented by this signed duration as a 32-bit float.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;fn as_millis_f64(self: &Self) -> f64Returns the number of milliseconds, with a possible fractional nanosecond component, represented by this signed duration as a 64-bit float.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;fn as_millis_f32(self: &Self) -> f32Returns the number of milliseconds, with a possible fractional nanosecond component, represented by this signed duration as a 32-bit float.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;fn from_secs_f64(secs: f64) -> SignedDurationReturns a signed duration corresponding to the number of seconds represented as a 64-bit float. The number given may have a fractional nanosecond component.
Panics
If the given float overflows the minimum or maximum signed duration values, then this panics.
Example
use SignedDuration; let duration = from_secs_f64; assert_eq!; assert_eq!; let duration = from_secs_f64; assert_eq!; assert_eq!; # Ok::fn from_secs_f32(secs: f32) -> SignedDurationReturns a signed duration corresponding to the number of seconds represented as a 32-bit float. The number given may have a fractional nanosecond component.
Panics
If the given float overflows the minimum or maximum signed duration values, then this panics.
Example
use SignedDuration; let duration = from_secs_f32; assert_eq!; // loss of precision! assert_eq!; let duration = from_secs_f32; assert_eq!; // loss of precision! assert_eq!; # Ok::fn try_from_secs_f64(secs: f64) -> Result<SignedDuration, Error>Returns a signed duration corresponding to the number of seconds represented as a 64-bit float. The number given may have a fractional nanosecond component.
If the given float overflows the minimum or maximum signed duration values, then an error is returned.
Example
use SignedDuration; let duration = try_from_secs_f64?; assert_eq!; assert_eq!; let duration = try_from_secs_f64?; assert_eq!; assert_eq!; assert!; assert!; assert!; assert!; assert!; # Ok::fn try_from_secs_f32(secs: f32) -> Result<SignedDuration, Error>Returns a signed duration corresponding to the number of seconds represented as a 32-bit float. The number given may have a fractional nanosecond component.
If the given float overflows the minimum or maximum signed duration values, then an error is returned.
Example
use SignedDuration; let duration = try_from_secs_f32?; assert_eq!; // loss of precision! assert_eq!; let duration = try_from_secs_f32?; assert_eq!; // loss of precision! assert_eq!; assert!; assert!; assert!; assert!; assert!; # Ok::fn mul_f64(self: Self, rhs: f64) -> SignedDurationReturns the result of multiplying this duration by the given 64-bit float.
Panics
This panics if the result is not finite or overflows a
SignedDuration.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!;fn mul_f32(self: Self, rhs: f32) -> SignedDurationReturns the result of multiplying this duration by the given 32-bit float.
Panics
This panics if the result is not finite or overflows a
SignedDuration.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!;fn div_f64(self: Self, rhs: f64) -> SignedDurationReturns the result of dividing this duration by the given 64-bit float.
Panics
This panics if the result is not finite or overflows a
SignedDuration.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!;fn div_f32(self: Self, rhs: f32) -> SignedDurationReturns the result of dividing this duration by the given 32-bit float.
Panics
This panics if the result is not finite or overflows a
SignedDuration.Example
use SignedDuration; let duration = new; assert_eq!; assert_eq!;fn div_duration_f64(self: Self, rhs: SignedDuration) -> f64Divides this signed duration by another signed duration and returns the corresponding 64-bit float result.
Example
use SignedDuration; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = new; let duration2 = new; assert_eq!;fn div_duration_f32(self: Self, rhs: SignedDuration) -> f32Divides this signed duration by another signed duration and returns the corresponding 32-bit float result.
Example
use SignedDuration; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = new; let duration2 = new; assert_eq!; let duration1 = new; let duration2 = new; assert_eq!;
impl SignedDuration
fn round<R: Into<SignedDurationRound>>(self: Self, options: R) -> Result<SignedDuration, Error>Returns a new signed duration that is rounded according to the given configuration.
Rounding a duration has a number of parameters, all of which are optional. When no parameters are given, then no rounding is done, and the duration as given is returned. That is, it's a no-op.
As is consistent with
SignedDurationitself, rounding only supports time units, i.e., units of hours or smaller. If a calendarUnitis provided, then an error is returned. In order to round a duration with calendar units, you must useSpan::roundand provide a relative datetime.The parameters are, in brief:
SignedDurationRound::smallestsets the smallestUnitthat is allowed to be non-zero in the duration returned. By default, it is set toUnit::Nanosecond, i.e., no rounding occurs. When the smallest unit is set to something bigger than nanoseconds, then the non-zero units in the duration smaller than the smallest unit are used to determine how the duration should be rounded. For example, rounding1 hour 59 minutesto the nearest hour using the default rounding mode would produce2 hours.SignedDurationRound::modedetermines how to handle the remainder when rounding. The default isRoundMode::HalfExpand, which corresponds to how you were likely taught to round in school. Alternative modes, likeRoundMode::Trunc, exist too. For example, a truncating rounding of1 hour 59 minutesto the nearest hour would produce1 hour.SignedDurationRound::incrementsets the rounding granularity to use for the configured smallest unit. For example, if the smallest unit is minutes and the increment is 5, then the duration returned will always have its minute units set to a multiple of5.
Errors
In general, there are two main ways for rounding to fail: an improper configuration like trying to round a duration to the nearest calendar unit, or when overflow occurs. Overflow can occur when the duration would exceed the minimum or maximum
SignedDurationvalues. Typically, this can only realistically happen if the duration before rounding is already close to its minimum or maximum value.Example: round to the nearest second
This shows how to round a duration to the nearest second. This might be useful when you want to chop off any sub-second component in a way that depends on how close it is (or not) to the next second.
use ; // rounds up let dur = new; assert_eq!; // rounds down let dur = new; assert_eq!; # Ok::Example: round to the nearest half minute
One can use
SignedDurationRound::incrementto set the rounding increment:use ; let options = new .smallest .increment; // rounds up let dur = from_secs; assert_eq!; // rounds down let dur = from_secs; assert_eq!; # Ok::Example: overflow results in an error
If rounding would result in a value that exceeds a
SignedDuration's minimum or maximum values, then an error occurs:use ; assert_eq!; assert_eq!;Example: rounding with a calendar unit results in an error
use ; assert_eq!;
impl SignedDuration
const fn as_hours(self: &Self) -> i64Returns the number of whole hours in this duration.
The value returned is negative when the duration is negative.
This does not include any fractional component corresponding to units less than an hour.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn as_mins(self: &Self) -> i64Returns the number of whole minutes in this duration.
The value returned is negative when the duration is negative.
This does not include any fractional component corresponding to units less than a minute.
Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!;const fn abs(self: Self) -> SignedDurationReturns the absolute value of this signed duration.
If this duration isn't negative, then this returns the original duration unchanged.
Panics
This panics when the seconds component of this signed duration is equal to
i64::MIN.Example
use SignedDuration; let duration = new; assert_eq!;const fn unsigned_abs(self: Self) -> DurationReturns the absolute value of this signed duration as a
std::time::Duration. More specifically, this routine cannot panic because the absolute value ofSignedDuration::MINis representable in astd::time::Duration.Example
use Duration; use SignedDuration; let duration = MIN; assert_eq!;const fn checked_neg(self: Self) -> Option<SignedDuration>Returns this duration with its sign flipped.
If this duration is zero, then this returns the duration unchanged.
This returns none if the negation does not exist. This occurs in precisely the cases when
SignedDuration::as_secsis equal toi64::MIN.Example
use SignedDuration; let duration = new; assert_eq!; let duration = new; assert_eq!; // Negating the minimum seconds isn't possible. assert_eq!;const fn signum(self: Self) -> i8Returns a number that represents the sign of this duration.
- When
SignedDuration::is_zerois true, this returns0. - When
SignedDuration::is_positiveis true, this returns1. - When
SignedDuration::is_negativeis true, this returns-1.
The above cases are mutually exclusive.
Example
use SignedDuration; assert_eq!;- When
const fn is_positive(self: &Self) -> boolReturns true when this duration is positive. That is, greater than
SignedDuration::ZERO.Example
use SignedDuration; let duration = new; assert!;const fn is_negative(self: &Self) -> boolReturns true when this duration is negative. That is, less than
SignedDuration::ZERO.Example
use SignedDuration; let duration = new; assert!;
impl SignedDuration
fn system_until(time1: SystemTime, time2: SystemTime) -> Result<SignedDuration, Error>Returns the duration from
time1untiltime2where the times arestd::time::SystemTimevalues from the standard library.Errors
This returns an error if the difference between the two time values overflows the signed duration limits.
Example
use ; use SignedDuration; let time1 = UNIX_EPOCH; let time2 = time1.checked_add.unwrap; assert_eq!; # Ok::
impl Add for SignedDuration
fn add(self: Self, rhs: SignedDuration) -> SignedDuration
impl AddAssign for SignedDuration
fn add_assign(self: &mut Self, rhs: SignedDuration)
impl Clone for SignedDuration
fn clone(self: &Self) -> SignedDuration
impl Copy for SignedDuration
impl Debug for SignedDuration
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for SignedDuration
fn default() -> SignedDuration
impl Display for SignedDuration
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Div for SignedDuration
fn div(self: Self, rhs: i32) -> SignedDuration
impl DivAssign for SignedDuration
fn div_assign(self: &mut Self, rhs: i32)
impl Eq for SignedDuration
impl Freeze for SignedDuration
impl From for SignedDuration
fn from(offset: Offset) -> SignedDuration
impl FromStr for SignedDuration
fn from_str(string: &str) -> Result<SignedDuration, Error>
impl Hash for SignedDuration
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Mul for SignedDuration
fn mul(self: Self, rhs: i32) -> SignedDuration
impl MulAssign for SignedDuration
fn mul_assign(self: &mut Self, rhs: i32)
impl Neg for SignedDuration
fn neg(self: Self) -> SignedDuration
impl Ord for SignedDuration
fn cmp(self: &Self, other: &SignedDuration) -> Ordering
impl PartialEq for SignedDuration
fn eq(self: &Self, other: &SignedDuration) -> bool
impl PartialOrd for SignedDuration
fn partial_cmp(self: &Self, other: &SignedDuration) -> Option<Ordering>
impl RefUnwindSafe for SignedDuration
impl Send for SignedDuration
impl Serialize for SignedDuration
fn serialize<S: serde::Serializer>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error>
impl StructuralPartialEq for SignedDuration
impl Sub for SignedDuration
fn sub(self: Self, rhs: SignedDuration) -> SignedDuration
impl SubAssign for SignedDuration
fn sub_assign(self: &mut Self, rhs: SignedDuration)
impl Sync for SignedDuration
impl TryFrom for SignedDuration
fn try_from(d: Duration) -> Result<SignedDuration, Error>
impl TryFrom for SignedDuration
fn try_from(sp: Span) -> Result<SignedDuration, Error>
impl Unpin for SignedDuration
impl UnsafeUnpin for SignedDuration
impl UnwindSafe for SignedDuration
impl<'de> Deserialize for SignedDuration
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<SignedDuration, <D as >::Error>
impl<T> Any for SignedDuration
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for SignedDuration
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for SignedDuration
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for SignedDuration
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> DeserializeOwned for SignedDuration
impl<T> From for SignedDuration
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for SignedDuration
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for SignedDuration
fn to_string(self: &Self) -> String
impl<T, U> Into for SignedDuration
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for SignedDuration
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for SignedDuration
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>