pub struct TimeDelta { /* private fields */ }Expand description
Implementationsยง
Sourceยงimpl TimeDelta
Additional APIs involving SystemInstant.
impl TimeDelta
Additional APIs involving SystemInstant.
Sourcepub fn after(&self, instant: SystemInstant) -> SystemInstant
Available on crate feature std only.
pub fn after(&self, instant: SystemInstant) -> SystemInstant
std only.Adds a TimeDelta to an instant, moving forward or backward in time.
ยงPanics
Panics if the result is outside the valid range of SystemInstant.
Sourcepub fn checked_after(&self, instant: SystemInstant) -> Option<SystemInstant> โ
Available on crate feature std only.
pub fn checked_after(&self, instant: SystemInstant) -> Option<SystemInstant> โ
std only.Adds a TimeDelta to an instant
Returns None if the result is outside the valid range.
Sourceยงimpl TimeDelta
ยงBasic methods
impl TimeDelta
ยงBasic methods
Sourcepub const fn new(secs: i64, nanos: i32) -> TimeDelta
pub const fn new(secs: i64, nanos: i32) -> TimeDelta
Creates a new TimeDelta from 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 nanos is less than 1_000_000_000.
Sourcepub const fn from_secs(secs: i64) -> TimeDelta
pub const fn from_secs(secs: i64) -> TimeDelta
Creates a new TimeDelta from the given number of whole seconds.
Sourcepub const fn from_millis(millis: i64) -> TimeDelta
pub const fn from_millis(millis: i64) -> TimeDelta
Creates a new TimeDelta from 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 time delta values. In
particular, TimeDelta::as_millis returns an i128, and this
may be a value that would otherwise overflow an i64.
Sourcepub const fn from_micros(micros: i64) -> TimeDelta
pub const fn from_micros(micros: i64) -> TimeDelta
Creates a new TimeDelta from 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 time delta values. In
particular, TimeDelta::as_micros returns an i128, and this
may be a value that would otherwise overflow an i64.
Sourcepub const fn from_nanos(nanos: i64) -> TimeDelta
pub const fn from_nanos(nanos: i64) -> TimeDelta
Creates a new TimeDelta from 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 time delta values. In
particular, TimeDelta::as_nanos returns an i128, which may
be a value that would otherwise overflow an i64.
Sourcepub const fn from_hours(hours: i64) -> TimeDelta
pub const fn from_hours(hours: i64) -> TimeDelta
Creates a new TimeDelta from the given number of hours.
Every hour is exactly 3,600 seconds.
ยงPanics
Panics if the number of hours, after being converted to nanoseconds,
overflows the minimum or maximum TimeDelta values.
Sourcepub const fn from_mins(minutes: i64) -> TimeDelta
pub const fn from_mins(minutes: i64) -> TimeDelta
Creates a new TimeDelta from the given number of minutes.
Every minute is exactly 60 seconds.
ยงPanics
Panics if the number of minutes, after being converted to nanoseconds,
overflows the minimum or maximum TimeDelta values.
Sourcepub const fn as_secs(&self) -> i64
pub const fn as_secs(&self) -> i64
Returns 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 subsec methods
such as TimeDelta::subsec_nanos.
Sourcepub const fn subsec_millis(&self) -> i32
pub const fn subsec_millis(&self) -> i32
Returns 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 TimeDelta::as_millis.
Sourcepub const fn subsec_micros(&self) -> i32
pub const fn subsec_micros(&self) -> i32
Returns 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 TimeDelta::as_micros.
Sourcepub const fn subsec_nanos(&self) -> i32
pub const fn subsec_nanos(&self) -> i32
Returns 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 TimeDelta::as_nanos.
Sourcepub const fn as_millis(&self) -> i128
pub const fn as_millis(&self) -> i128
Returns 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 TimeDelta::subsec_millis.
Sourcepub const fn as_micros(&self) -> i128
pub const fn as_micros(&self) -> i128
Returns 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 TimeDelta::subsec_micros.
Sourcepub const fn as_nanos(&self) -> i128
pub const fn as_nanos(&self) -> i128
Returns 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 TimeDelta::subsec_nanos.
Sourceยงimpl TimeDelta
Additional methods not found in the standard library.
impl TimeDelta
Additional methods not found in the standard library.
In most cases, these APIs exist as a result of the fact that this duration is signed.
Sourcepub const fn as_hours(&self) -> i64
pub const fn as_hours(&self) -> i64
Returns 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.
Sourcepub const fn as_mins(&self) -> i64
pub const fn as_mins(&self) -> i64
Returns 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.
Sourcepub const fn abs(self) -> TimeDelta
pub const fn abs(self) -> TimeDelta
Returns the absolute value of this time delta.
If this duration is positive, then this returns the original duration unchanged.
ยงPanics
This panics when the seconds component of this time delta is equal to i64::MIN.
Sourcepub const fn neg_abs(self) -> TimeDelta
pub const fn neg_abs(self) -> TimeDelta
Returns the negative absolute value of this time delta.
If this duration is negative, then this returns the original duration unchanged.
ยงPanics
This panics when the seconds component of this time delta is equal to i64::MIN.
Sourcepub const fn checked_neg(self) -> Option<TimeDelta> โ
pub const fn checked_neg(self) -> Option<TimeDelta> โ
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 TimeDelta::as_secs is equal to i64::MIN.
Sourcepub const fn signum(self) -> i8
pub const fn signum(self) -> i8
Returns a number that represents the sign of this duration.
- When
TimeDelta::is_zerois true, this returns0. - When
TimeDelta::is_positiveis true, this returns1. - When
TimeDelta::is_negativeis true, this returns-1.
The above cases are mutually exclusive.
Sourcepub const fn is_positive(&self) -> bool
pub const fn is_positive(&self) -> bool
Returns true when this duration is positive. That is, greater than TimeDelta::ZERO.
Sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Returns true when this duration is negative. That is, less than TimeDelta::ZERO.
Sourceยงimpl TimeDelta
ยงOperations.
impl TimeDelta
ยงOperations.
Sourcepub const fn checked_add(self, rhs: TimeDelta) -> Option<TimeDelta> โ
pub const fn checked_add(self, rhs: TimeDelta) -> Option<TimeDelta> โ
Add two time deltas together. If overflow occurs, then None is returned.
Sourcepub const fn saturating_add(self, rhs: TimeDelta) -> TimeDelta
pub const fn saturating_add(self, rhs: TimeDelta) -> TimeDelta
Add two time deltas together. If overflow occurs, then arithmetic saturates.
Sourcepub const fn checked_sub(self, rhs: TimeDelta) -> Option<TimeDelta> โ
pub const fn checked_sub(self, rhs: TimeDelta) -> Option<TimeDelta> โ
Subtract one time delta from another. If overflow occurs, then None is returned.
Sourcepub const fn saturating_sub(self, rhs: TimeDelta) -> TimeDelta
pub const fn saturating_sub(self, rhs: TimeDelta) -> TimeDelta
Add two time deltas together. If overflow occurs, then arithmetic saturates.
Sourceยงimpl TimeDelta
ยงOperations involving integers.
impl TimeDelta
ยงOperations involving integers.
Sourcepub const fn checked_mul(self, rhs: i32) -> Option<TimeDelta> โ
pub const fn checked_mul(self, rhs: i32) -> Option<TimeDelta> โ
Multiply this time delta by an integer.
If the multiplication overflows, then None is returned.
Sourcepub const fn saturating_mul(self, rhs: i32) -> TimeDelta
pub const fn saturating_mul(self, rhs: i32) -> TimeDelta
Multiply this time delta 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.
Sourceยงimpl TimeDelta
ยงOperations involving floating-point numbers.
impl TimeDelta
ยงOperations involving floating-point numbers.
Sourcepub const fn as_secs_f64(&self) -> f64
pub const fn as_secs_f64(&self) -> f64
Returns the number of seconds, with a possible fractional nanosecond component.
Sourcepub const fn as_secs_f32(&self) -> f32
pub const fn as_secs_f32(&self) -> f32
Returns the number of seconds, with a possible fractional nanosecond component.
Sourcepub const fn from_secs_f64(secs: f64) -> TimeDelta
pub const fn from_secs_f64(secs: f64) -> TimeDelta
Returns a time delta corresponding to the number of seconds.
The number given may have a fractional nanosecond component.
ยงPanics
Panics if the given float overflows the minimum or maximum time delta values.
Sourcepub const fn from_secs_f32(secs: f32) -> TimeDelta
pub const fn from_secs_f32(secs: f32) -> TimeDelta
Returns a time delta corresponding to the number of seconds.
The number given may have a fractional nanosecond component.
ยงPanics
Panics if the given float overflows the minimum or maximum time delta values.
Sourcepub const fn try_from_secs_f64(secs: f64) -> Result<TimeDelta, &'static str> โ
pub const fn try_from_secs_f64(secs: f64) -> Result<TimeDelta, &'static str> โ
Returns a time delta corresponding to the number of seconds.
The number given may have a fractional nanosecond component.
If the given float overflows the minimum or maximum time delta values, then an error is returned.
Sourcepub const fn try_from_secs_f32(secs: f32) -> Result<TimeDelta, &'static str> โ
pub const fn try_from_secs_f32(secs: f32) -> Result<TimeDelta, &'static str> โ
Returns a time delta corresponding to the number of seconds.
The number given may have a fractional nanosecond component.
Returns an error if the given float overflows the minimum or maximum time delta values.
Sourcepub const fn as_millis_f64(&self) -> f64
pub const fn as_millis_f64(&self) -> f64
Returns the number of milliseconds, with a possible fractional nanosecond component.
Sourcepub const fn as_millis_f32(&self) -> f32
pub const fn as_millis_f32(&self) -> f32
Returns the number of milliseconds, with a possible fractional nanosecond component.
Sourcepub const fn from_millis_f64(millis: f64) -> TimeDelta
pub const fn from_millis_f64(millis: f64) -> TimeDelta
Returns a time delta corresponding to the number of milliseconds.
The number given may have a fractional nanosecond component.
ยงPanics
Panics if the given float overflows the minimum or maximum time delta values.
Sourcepub const fn try_from_millis_f64(millis: f64) -> Result<TimeDelta, &'static str> โ
pub const fn try_from_millis_f64(millis: f64) -> Result<TimeDelta, &'static str> โ
Returns a time delta corresponding to the number of milliseconds.
The number given may have a fractional nanosecond component.
Returns an error if the given float overflows the minimum or maximum time delta values.
Sourcepub const fn mul_f64(self, rhs: f64) -> TimeDelta
pub const fn mul_f64(self, rhs: f64) -> TimeDelta
Returns the result of multiplying this duration by the given 64-bit float.
ยงPanics
This panics if the result is not finite or overflows a TimeDelta.
Sourcepub const fn mul_f32(self, rhs: f32) -> TimeDelta
pub const fn mul_f32(self, rhs: f32) -> TimeDelta
Returns the result of multiplying this duration by the given 32-bit float.
ยงPanics
This panics if the result is not finite or overflows a TimeDelta.
Sourcepub const fn div_f64(self, rhs: f64) -> TimeDelta
pub const fn div_f64(self, rhs: f64) -> TimeDelta
Returns the result of dividing this duration by the given f64.
ยงPanics
This panics if the result is not finite or overflows a TimeDelta.
Sourcepub const fn div_f32(self, rhs: f32) -> TimeDelta
pub const fn div_f32(self, rhs: f32) -> TimeDelta
Returns the result of dividing this duration by the given f32.
ยงPanics
This panics if the result is not finite or overflows a TimeDelta.
Sourcepub const fn div_delta_f64(self, rhs: TimeDelta) -> f64
pub const fn div_delta_f64(self, rhs: TimeDelta) -> f64
Divides this time delta by another time delta.
Sourcepub const fn div_delta_f32(self, rhs: TimeDelta) -> f32
pub const fn div_delta_f32(self, rhs: TimeDelta) -> f32
Divides this time delta by another time delta.
Sourceยงimpl TimeDelta
impl TimeDelta
Sourcepub const fn from_duration(duration: Duration) -> Self
pub const fn from_duration(duration: Duration) -> Self
Converts a Duration to a TimeDelta.
Sourcepub const fn to_duration(&self) -> Option<Duration> โ
pub const fn to_duration(&self) -> Option<Duration> โ
Converts a TimeDelta to a Duration if it is non-negative.
Returns None if the TimeDelta is negative.
Sourcepub const fn abs_duration(self) -> Duration
pub const fn abs_duration(self) -> Duration
Returns the absolute value of this time delta as a Duration.
This method cannot panic because the absolute value of TimeDelta::MIN
is always representable in a Duration.
Sourcepub const fn checked_add_duration(&self, duration: Duration) -> Option<Self> โ
pub const fn checked_add_duration(&self, duration: Duration) -> Option<Self> โ
Adds a Duration to this TimeDelta.
Returns None if the result overflows.
Sourcepub const fn checked_sub_duration(&self, duration: Duration) -> Option<Self> โ
pub const fn checked_sub_duration(&self, duration: Duration) -> Option<Self> โ
Subtracts a Duration from this TimeDelta.
Returns None if the result underflows.
Sourceยงimpl TimeDelta
impl TimeDelta
Trait Implementationsยง
Sourceยงimpl Add<TimeDelta> for SystemInstant
Available on crate feature std only.Shifts Instant forward or backward.
impl Add<TimeDelta> for SystemInstant
std only.Shifts Instant forward or backward.
Sourceยงimpl AddAssign for TimeDelta
impl AddAssign for TimeDelta
Sourceยงfn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moreimpl Copy for TimeDelta
Sourceยงimpl DivAssign<i32> for TimeDelta
impl DivAssign<i32> for TimeDelta
Sourceยงfn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
/= operation. Read moreimpl Eq for TimeDelta
Sourceยงimpl MulAssign<i32> for TimeDelta
impl MulAssign<i32> for TimeDelta
Sourceยงfn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
*= operation. Read moreSourceยงimpl Ord for TimeDelta
impl Ord for TimeDelta
1.21.0 (const: unstable) ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl PartialEq for TimeDelta
impl PartialEq for TimeDelta
Sourceยงimpl PartialOrd for TimeDelta
impl PartialOrd for TimeDelta
impl StructuralPartialEq for TimeDelta
Sourceยงimpl Sub<Instant> for TimeDelta
Available on crate feature std only.Returns a signed TimeDelta.
impl Sub<Instant> for TimeDelta
std only.Returns a signed TimeDelta.
Sourceยงfn sub(self, rhs: SystemInstant) -> SystemInstant
fn sub(self, rhs: SystemInstant) -> SystemInstant
- operation. Read moreSourceยงimpl Sub<TimeDelta> for SystemInstant
Available on crate feature std only.Moves Instant backward or forward.
impl Sub<TimeDelta> for SystemInstant
std only.Moves Instant backward or forward.
Sourceยงimpl SubAssign for TimeDelta
impl SubAssign for TimeDelta
Sourceยงfn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read moreSourceยงimpl TimeSpan for TimeDelta
impl TimeSpan for TimeDelta
Sourceยงfn time_add_checked(self, other: Self) -> Option<Self> โ
fn time_add_checked(self, other: Self) -> Option<Self> โ
None if it is not representable.Sourceยงfn time_sub_checked(self, other: Self) -> Option<Self> โ
fn time_sub_checked(self, other: Self) -> Option<Self> โ
None if it is not representable.Sourceยงfn time_is_zero(self) -> bool
fn time_is_zero(self) -> bool
Sourceยงimpl TryFrom<LinuxTimespec> for TimeDelta
Available on crate feature linux only.
impl TryFrom<LinuxTimespec> for TimeDelta
linux only.Auto Trait Implementationsยง
impl Freeze for TimeDelta
impl RefUnwindSafe for TimeDelta
impl Send for TimeDelta
impl Sync for TimeDelta
impl Unpin for TimeDelta
impl UnsafeUnpin for TimeDelta
impl UnwindSafe for TimeDelta
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
unsafe_slice only.