pub struct Duration { /* private fields */ }
Expand description
A span of time with nanosecond precision.
Each Duration
is composed of a whole number of seconds and a fractional
part represented in nanoseconds.
Duration
implements many traits, including Add
, Sub
, Mul
, and
Div
, among others.
This implementation allows for negative durations, unlike
core::time::Duration
.
Implementations
sourceimpl Duration
impl Duration
sourcepub const fn zero() -> Self
pub const fn zero() -> Self
Equivalent to 0.seconds()
.
assert_eq!(Duration::zero(), 0.seconds());
sourcepub const fn nanosecond() -> Self
pub const fn nanosecond() -> Self
Equivalent to 1.nanoseconds()
.
assert_eq!(Duration::nanosecond(), 1.nanoseconds());
sourcepub const fn microsecond() -> Self
pub const fn microsecond() -> Self
Equivalent to 1.microseconds()
.
assert_eq!(Duration::microsecond(), 1.microseconds());
sourcepub const fn millisecond() -> Self
pub const fn millisecond() -> Self
Equivalent to 1.milliseconds()
.
assert_eq!(Duration::millisecond(), 1.milliseconds());
sourcepub const fn second() -> Self
pub const fn second() -> Self
Equivalent to 1.seconds()
.
assert_eq!(Duration::second(), 1.seconds());
sourcepub const fn minute() -> Self
pub const fn minute() -> Self
Equivalent to 1.minutes()
.
assert_eq!(Duration::minute(), 1.minutes());
sourcepub const fn max_value() -> Self
pub const fn max_value() -> Self
The maximum possible duration. Adding any positive duration to this will cause an overflow.
The value returned by this method may change at any time.
sourcepub const fn min_value() -> Self
pub const fn min_value() -> Self
The minimum possible duration. Adding any negative duration to this will cause an overflow.
The value returned by this method may change at any time.
sourcepub const fn is_zero(self) -> bool
pub const fn is_zero(self) -> bool
Check if a duration is exactly zero.
assert!(0.seconds().is_zero());
assert!(!1.nanoseconds().is_zero());
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Check if a duration is negative.
assert!((-1).seconds().is_negative());
assert!(!0.seconds().is_negative());
assert!(!1.seconds().is_negative());
sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Check if a duration is positive.
assert!(1.seconds().is_positive());
assert!(!0.seconds().is_positive());
assert!(!(-1).seconds().is_positive());
sourcepub fn sign(self) -> Sign
👎 Deprecated since 0.2.7: To obtain the sign of a Duration
, you should use the is_positive
, is_negative
, and is_zero
methods.
pub fn sign(self) -> Sign
To obtain the sign of a Duration
, you should use the is_positive
, is_negative
, and is_zero
methods.
Get the sign of the duration.
assert_eq!(1.seconds().sign(), Sign::Positive);
assert_eq!((-1).seconds().sign(), Sign::Negative);
assert_eq!(0.seconds().sign(), Sign::Zero);
sourcepub const fn abs(self) -> Self
pub const fn abs(self) -> Self
Get the absolute value of the duration.
assert_eq!(1.seconds().abs(), 1.seconds());
assert_eq!(0.seconds().abs(), 0.seconds());
assert_eq!((-1).seconds().abs(), 1.seconds());
This function is const fn
when using rustc >= 1.39.
sourcepub const fn new(seconds: i64, nanoseconds: i32) -> Self
pub const fn new(seconds: i64, nanoseconds: i32) -> Self
Create a new Duration
with the provided seconds and nanoseconds. If
nanoseconds is at least ±109, it will wrap to the number of
seconds.
assert_eq!(Duration::new(1, 0), 1.seconds());
assert_eq!(Duration::new(-1, 0), (-1).seconds());
assert_eq!(Duration::new(1, 2_000_000_000), 3.seconds());
sourcepub const fn weeks(weeks: i64) -> Self
pub const fn weeks(weeks: i64) -> Self
Create a new Duration
with the given number of weeks. Equivalent to
Duration::seconds(weeks * 604_800)
.
assert_eq!(Duration::weeks(1), 604_800.seconds());
sourcepub const fn whole_weeks(self) -> i64
pub const fn whole_weeks(self) -> i64
Get the number of whole weeks in the duration.
assert_eq!(1.weeks().whole_weeks(), 1);
assert_eq!((-1).weeks().whole_weeks(), -1);
assert_eq!(6.days().whole_weeks(), 0);
assert_eq!((-6).days().whole_weeks(), 0);
sourcepub const fn days(days: i64) -> Self
pub const fn days(days: i64) -> Self
Create a new Duration
with the given number of days. Equivalent to
Duration::seconds(days * 86_400)
.
assert_eq!(Duration::days(1), 86_400.seconds());
sourcepub const fn whole_days(self) -> i64
pub const fn whole_days(self) -> i64
Get the number of whole days in the duration.
assert_eq!(1.days().whole_days(), 1);
assert_eq!((-1).days().whole_days(), -1);
assert_eq!(23.hours().whole_days(), 0);
assert_eq!((-23).hours().whole_days(), 0);
sourcepub const fn hours(hours: i64) -> Self
pub const fn hours(hours: i64) -> Self
Create a new Duration
with the given number of hours. Equivalent to
Duration::seconds(hours * 3_600)
.
assert_eq!(Duration::hours(1), 3_600.seconds());
sourcepub const fn whole_hours(self) -> i64
pub const fn whole_hours(self) -> i64
Get the number of whole hours in the duration.
assert_eq!(1.hours().whole_hours(), 1);
assert_eq!((-1).hours().whole_hours(), -1);
assert_eq!(59.minutes().whole_hours(), 0);
assert_eq!((-59).minutes().whole_hours(), 0);
sourcepub const fn minutes(minutes: i64) -> Self
pub const fn minutes(minutes: i64) -> Self
Create a new Duration
with the given number of minutes. Equivalent to
Duration::seconds(minutes * 60)
.
assert_eq!(Duration::minutes(1), 60.seconds());
sourcepub const fn whole_minutes(self) -> i64
pub const fn whole_minutes(self) -> i64
Get the number of whole minutes in the duration.
assert_eq!(1.minutes().whole_minutes(), 1);
assert_eq!((-1).minutes().whole_minutes(), -1);
assert_eq!(59.seconds().whole_minutes(), 0);
assert_eq!((-59).seconds().whole_minutes(), 0);
sourcepub const fn seconds(seconds: i64) -> Self
pub const fn seconds(seconds: i64) -> Self
Create a new Duration
with the given number of seconds.
assert_eq!(Duration::seconds(1), 1_000.milliseconds());
sourcepub const fn whole_seconds(self) -> i64
pub const fn whole_seconds(self) -> i64
Get the number of whole seconds in the duration.
assert_eq!(1.seconds().whole_seconds(), 1);
assert_eq!((-1).seconds().whole_seconds(), -1);
assert_eq!(1.minutes().whole_seconds(), 60);
assert_eq!((-1).minutes().whole_seconds(), -60);
sourcepub fn seconds_f64(seconds: f64) -> Self
pub fn seconds_f64(seconds: f64) -> Self
Creates a new Duration
from the specified number of seconds
represented as f64
.
assert_eq!(Duration::seconds_f64(0.5), 0.5.seconds());
assert_eq!(Duration::seconds_f64(-0.5), -0.5.seconds());
sourcepub fn as_seconds_f64(self) -> f64
pub fn as_seconds_f64(self) -> f64
Get the number of fractional seconds in the duration.
assert_eq!(1.5.seconds().as_seconds_f64(), 1.5);
assert_eq!((-1.5).seconds().as_seconds_f64(), -1.5);
sourcepub fn seconds_f32(seconds: f32) -> Self
pub fn seconds_f32(seconds: f32) -> Self
Creates a new Duration
from the specified number of seconds
represented as f32
.
assert_eq!(Duration::seconds_f32(0.5), 0.5.seconds());
assert_eq!(Duration::seconds_f32(-0.5), (-0.5).seconds());
sourcepub fn as_seconds_f32(self) -> f32
pub fn as_seconds_f32(self) -> f32
Get the number of fractional seconds in the duration.
assert_eq!(1.5.seconds().as_seconds_f32(), 1.5);
assert_eq!((-1.5).seconds().as_seconds_f32(), -1.5);
sourcepub const fn milliseconds(milliseconds: i64) -> Self
pub const fn milliseconds(milliseconds: i64) -> Self
Create a new Duration
with the given number of milliseconds.
assert_eq!(Duration::milliseconds(1), 1_000.microseconds());
assert_eq!(Duration::milliseconds(-1), (-1_000).microseconds());
sourcepub const fn whole_milliseconds(self) -> i128
pub const fn whole_milliseconds(self) -> i128
Get the number of whole milliseconds in the duration.
assert_eq!(1.seconds().whole_milliseconds(), 1_000);
assert_eq!((-1).seconds().whole_milliseconds(), -1_000);
assert_eq!(1.milliseconds().whole_milliseconds(), 1);
assert_eq!((-1).milliseconds().whole_milliseconds(), -1);
sourcepub const fn subsec_milliseconds(self) -> i16
pub const fn subsec_milliseconds(self) -> i16
Get the number of milliseconds past the number of whole seconds.
Always in the range -1_000..1_000
.
assert_eq!(1.4.seconds().subsec_milliseconds(), 400);
assert_eq!((-1.4).seconds().subsec_milliseconds(), -400);
sourcepub const fn microseconds(microseconds: i64) -> Self
pub const fn microseconds(microseconds: i64) -> Self
Create a new Duration
with the given number of microseconds.
assert_eq!(Duration::microseconds(1), 1_000.nanoseconds());
assert_eq!(Duration::microseconds(-1), (-1_000).nanoseconds());
sourcepub const fn whole_microseconds(self) -> i128
pub const fn whole_microseconds(self) -> i128
Get the number of whole microseconds in the duration.
assert_eq!(1.milliseconds().whole_microseconds(), 1_000);
assert_eq!((-1).milliseconds().whole_microseconds(), -1_000);
assert_eq!(1.microseconds().whole_microseconds(), 1);
assert_eq!((-1).microseconds().whole_microseconds(), -1);
sourcepub const fn subsec_microseconds(self) -> i32
pub const fn subsec_microseconds(self) -> i32
Get the number of microseconds past the number of whole seconds.
Always in the range -1_000_000..1_000_000
.
assert_eq!(1.0004.seconds().subsec_microseconds(), 400);
assert_eq!((-1.0004).seconds().subsec_microseconds(), -400);
sourcepub const fn nanoseconds(nanoseconds: i64) -> Self
pub const fn nanoseconds(nanoseconds: i64) -> Self
Create a new Duration
with the given number of nanoseconds.
assert_eq!(Duration::nanoseconds(1), 1.microseconds() / 1_000);
assert_eq!(Duration::nanoseconds(-1), (-1).microseconds() / 1_000);
sourcepub const fn whole_nanoseconds(self) -> i128
pub const fn whole_nanoseconds(self) -> i128
Get the number of nanoseconds in the duration.
assert_eq!(1.microseconds().whole_nanoseconds(), 1_000);
assert_eq!((-1).microseconds().whole_nanoseconds(), -1_000);
assert_eq!(1.nanoseconds().whole_nanoseconds(), 1);
assert_eq!((-1).nanoseconds().whole_nanoseconds(), -1);
sourcepub const fn subsec_nanoseconds(self) -> i32
pub const fn subsec_nanoseconds(self) -> i32
Get the number of nanoseconds past the number of whole seconds.
The returned value will always be in the range
-1_000_000_000..1_000_000_000
.
assert_eq!(1.000_000_400.seconds().subsec_nanoseconds(), 400);
assert_eq!((-1.000_000_400).seconds().subsec_nanoseconds(), -400);
sourcepub fn checked_add(self, rhs: Self) -> Option<Self>
pub fn checked_add(self, rhs: Self) -> Option<Self>
Computes self + rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_add(5.seconds()), Some(10.seconds()));
assert_eq!(Duration::max_value().checked_add(1.nanoseconds()), None);
assert_eq!((-5).seconds().checked_add(5.seconds()), Some(0.seconds()));
sourcepub fn checked_sub(self, rhs: Self) -> Option<Self>
pub fn checked_sub(self, rhs: Self) -> Option<Self>
Computes self - rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_sub(5.seconds()), Some(Duration::zero()));
assert_eq!(Duration::min_value().checked_sub(1.nanoseconds()), None);
assert_eq!(5.seconds().checked_sub(10.seconds()), Some((-5).seconds()));
sourcepub fn checked_mul(self, rhs: i32) -> Option<Self>
pub fn checked_mul(self, rhs: i32) -> Option<Self>
Computes self * rhs
, returning None
if an overflow occurred.
assert_eq!(5.seconds().checked_mul(2), Some(10.seconds()));
assert_eq!(5.seconds().checked_mul(-2), Some((-10).seconds()));
assert_eq!(5.seconds().checked_mul(0), Some(0.seconds()));
assert_eq!(Duration::max_value().checked_mul(2), None);
assert_eq!(Duration::min_value().checked_mul(2), None);
sourcepub const fn checked_div(self, rhs: i32) -> Option<Self>
pub const fn checked_div(self, rhs: i32) -> Option<Self>
Computes self / rhs
, returning None
if rhs == 0
.
assert_eq!(10.seconds().checked_div(2), Some(5.seconds()));
assert_eq!(10.seconds().checked_div(-2), Some((-5).seconds()));
assert_eq!(1.seconds().checked_div(0), None);
This function is const fn
when using rustc >= 1.46.
Trait Implementations
sourceimpl Add<Duration> for StdDuration
impl Add<Duration> for StdDuration
sourceimpl Add<Duration> for StdInstant
impl Add<Duration> for StdInstant
sourceimpl Add<Duration> for OffsetDateTime
impl Add<Duration> for OffsetDateTime
sourceimpl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
sourceimpl Add<Duration> for PrimitiveDateTime
impl Add<Duration> for PrimitiveDateTime
sourceimpl Add<Duration> for Time
impl Add<Duration> for Time
sourcefn add(self, duration: Duration) -> Self::Output
fn add(self, duration: Duration) -> Self::Output
Add the sub-day time of the Duration
to the Time
. Wraps on overflow.
assert_eq!(time!(12:00) + 2.hours(), time!(14:00));
assert_eq!(time!(0:00:01) + (-2).seconds(), time!(23:59:59));
type Output = Self
type Output = Self
The resulting type after applying the +
operator.
sourceimpl AddAssign<Duration> for Date
impl AddAssign<Duration> for Date
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
sourcefn add_assign(&mut self, rhs: StdDuration)
fn add_assign(&mut self, rhs: StdDuration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for StdInstant
impl AddAssign<Duration> for StdInstant
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for OffsetDateTime
impl AddAssign<Duration> for OffsetDateTime
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for SystemTime
impl AddAssign<Duration> for SystemTime
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for PrimitiveDateTime
impl AddAssign<Duration> for PrimitiveDateTime
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
sourcefn add_assign(&mut self, duration: Duration)
fn add_assign(&mut self, duration: Duration)
Add the sub-day time of the Duration
to the existing Time
. Wraps on
overflow.
let mut time = time!(12:00);
time += 2.hours();
assert_eq!(time, time!(14:00));
let mut time = time!(0:00:01);
time += (-2).seconds();
assert_eq!(time, time!(23:59:59));
sourceimpl Div<Duration> for StdDuration
impl Div<Duration> for StdDuration
sourceimpl DivAssign<f32> for Duration
impl DivAssign<f32> for Duration
sourcefn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the /=
operation. Read more
sourceimpl DivAssign<f64> for Duration
impl DivAssign<f64> for Duration
sourcefn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
Performs the /=
operation. Read more
sourceimpl DivAssign<i16> for Duration
impl DivAssign<i16> for Duration
sourcefn div_assign(&mut self, rhs: i16)
fn div_assign(&mut self, rhs: i16)
Performs the /=
operation. Read more
sourceimpl DivAssign<i32> for Duration
impl DivAssign<i32> for Duration
sourcefn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
Performs the /=
operation. Read more
sourceimpl DivAssign<i8> for Duration
impl DivAssign<i8> for Duration
sourcefn div_assign(&mut self, rhs: i8)
fn div_assign(&mut self, rhs: i8)
Performs the /=
operation. Read more
sourceimpl DivAssign<u16> for Duration
impl DivAssign<u16> for Duration
sourcefn div_assign(&mut self, rhs: u16)
fn div_assign(&mut self, rhs: u16)
Performs the /=
operation. Read more
sourceimpl DivAssign<u32> for Duration
impl DivAssign<u32> for Duration
sourcefn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
Performs the /=
operation. Read more
sourceimpl DivAssign<u8> for Duration
impl DivAssign<u8> for Duration
sourcefn div_assign(&mut self, rhs: u8)
fn div_assign(&mut self, rhs: u8)
Performs the /=
operation. Read more
sourceimpl MulAssign<f32> for Duration
impl MulAssign<f32> for Duration
sourcefn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the *=
operation. Read more
sourceimpl MulAssign<f64> for Duration
impl MulAssign<f64> for Duration
sourcefn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the *=
operation. Read more
sourceimpl MulAssign<i16> for Duration
impl MulAssign<i16> for Duration
sourcefn mul_assign(&mut self, rhs: i16)
fn mul_assign(&mut self, rhs: i16)
Performs the *=
operation. Read more
sourceimpl MulAssign<i32> for Duration
impl MulAssign<i32> for Duration
sourcefn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
Performs the *=
operation. Read more
sourceimpl MulAssign<i8> for Duration
impl MulAssign<i8> for Duration
sourcefn mul_assign(&mut self, rhs: i8)
fn mul_assign(&mut self, rhs: i8)
Performs the *=
operation. Read more
sourceimpl MulAssign<u16> for Duration
impl MulAssign<u16> for Duration
sourcefn mul_assign(&mut self, rhs: u16)
fn mul_assign(&mut self, rhs: u16)
Performs the *=
operation. Read more
sourceimpl MulAssign<u32> for Duration
impl MulAssign<u32> for Duration
sourcefn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
Performs the *=
operation. Read more
sourceimpl MulAssign<u8> for Duration
impl MulAssign<u8> for Duration
sourcefn mul_assign(&mut self, rhs: u8)
fn mul_assign(&mut self, rhs: u8)
Performs the *=
operation. Read more
sourceimpl Ord for Duration
impl Ord for Duration
sourceimpl PartialEq<Duration> for StdDuration
impl PartialEq<Duration> for StdDuration
sourceimpl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
sourcefn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
sourcefn partial_cmp(&self, rhs: &StdDuration) -> Option<Ordering>
fn partial_cmp(&self, rhs: &StdDuration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PartialOrd<Duration> for StdDuration
impl PartialOrd<Duration> for StdDuration
sourcefn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Sub<Duration> for StdDuration
impl Sub<Duration> for StdDuration
sourceimpl Sub<Duration> for StdInstant
impl Sub<Duration> for StdInstant
sourceimpl Sub<Duration> for OffsetDateTime
impl Sub<Duration> for OffsetDateTime
sourceimpl Sub<Duration> for SystemTime
impl Sub<Duration> for SystemTime
sourceimpl Sub<Duration> for PrimitiveDateTime
impl Sub<Duration> for PrimitiveDateTime
sourceimpl Sub<Duration> for Time
impl Sub<Duration> for Time
sourcefn sub(self, duration: Duration) -> Self::Output
fn sub(self, duration: Duration) -> Self::Output
Subtract the sub-day time of the Duration
from the Time
. Wraps on
overflow.
assert_eq!(
time!(14:00) - 2.hours(),
time!(12:00)
);
assert_eq!(
time!(23:59:59) - (-2).seconds(),
time!(0:00:01)
);
type Output = Self
type Output = Self
The resulting type after applying the -
operator.
sourceimpl SubAssign<Duration> for Date
impl SubAssign<Duration> for Date
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
sourcefn sub_assign(&mut self, rhs: StdDuration)
fn sub_assign(&mut self, rhs: StdDuration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for StdDuration
impl SubAssign<Duration> for StdDuration
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for StdInstant
impl SubAssign<Duration> for StdInstant
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for OffsetDateTime
impl SubAssign<Duration> for OffsetDateTime
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for SystemTime
impl SubAssign<Duration> for SystemTime
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for PrimitiveDateTime
impl SubAssign<Duration> for PrimitiveDateTime
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
sourcefn sub_assign(&mut self, duration: Duration)
fn sub_assign(&mut self, duration: Duration)
Subtract the sub-day time of the Duration
from the existing Time
.
Wraps on overflow.
let mut time = time!(14:00);
time -= 2.hours();
assert_eq!(time, time!(12:00));
let mut time = time!(23:59:59);
time -= (-2).seconds();
assert_eq!(time, time!(0:00:01));
sourceimpl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
type Error = ConversionRange
type Error = ConversionRange
The type returned in the event of a conversion error.
sourcefn try_from(original: StdDuration) -> Result<Self, ConversionRange>
fn try_from(original: StdDuration) -> Result<Self, ConversionRange>
Performs the conversion.
sourceimpl TryFrom<Duration> for StdDuration
impl TryFrom<Duration> for StdDuration
type Error = ConversionRange
type Error = ConversionRange
The type returned in the event of a conversion error.
sourcefn try_from(duration: Duration) -> Result<Self, ConversionRange>
fn try_from(duration: Duration) -> Result<Self, ConversionRange>
Performs the conversion.
impl Copy for Duration
impl Eq for Duration
impl StructuralEq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more