Expand description
Represents an instant in time.
The generic T
can either be u32
or u64
, and the const generics represent the ratio of the
ticks contained within the instant: instant in seconds = NOM / DENOM * ticks
Implementations
impl<const NOM: u32, const DENOM: u32> Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Instant<u32, NOM, DENOM>
pub const fn from_ticks(ticks: u32) -> Instant<u32, NOM, DENOM>
pub const fn from_ticks(ticks: u32) -> Instant<u32, NOM, DENOM>
Create an Instant
from a ticks value.
let _i = Instant::<u32, 1, 1_000>::from_ticks(1);
pub const fn ticks(&self) -> u32
pub const fn ticks(&self) -> u32
Extract the ticks from an Instant
.
let i = Instant::<u32, 1, 1_000>::from_ticks(234);
assert_eq!(i.ticks(), 234);
pub const fn const_cmp(self, other: Instant<u32, NOM, DENOM>) -> Ordering
pub const fn const_cmp(self, other: Instant<u32, NOM, DENOM>) -> Ordering
Const comparison of Instant
s.
let i1 = Instant::<u32, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u32, 1, 1_000>::from_ticks(2);
assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);
pub const fn duration_since_epoch(self) -> Duration<u32, NOM, DENOM>
pub const fn duration_since_epoch(self) -> Duration<u32, NOM, DENOM>
Duration between since the start of the Instant
. This assumes an instant which
won’t wrap within the execution of the program.
let i = Instant::<u32, 1, 1_000>::from_ticks(11);
assert_eq!(i.duration_since_epoch().ticks(), 11);
pub const fn checked_duration_since(
self,
other: Instant<u32, NOM, DENOM>
) -> Option<Duration<u32, NOM, DENOM>>
pub const fn checked_duration_since(
self,
other: Instant<u32, NOM, DENOM>
) -> Option<Duration<u32, NOM, DENOM>>
Duration between Instant
s.
let i1 = Instant::<u32, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u32, 1, 1_000>::from_ticks(2);
assert_eq!(i1.checked_duration_since(i2), None);
assert_eq!(i2.checked_duration_since(i1).unwrap().ticks(), 1);
pub const fn checked_sub_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u32, O_NOM, O_DENOM>
) -> Option<Instant<u32, NOM, DENOM>>
pub const fn checked_sub_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u32, O_NOM, O_DENOM>
) -> Option<Instant<u32, NOM, DENOM>>
Subtract a Duration
from an Instant
while checking for overflow.
let i = Instant::<u32, 1, 1_000>::from_ticks(1);
let d = Duration::<u32, 1, 1_000>::from_ticks(1);
assert_eq!(i.checked_sub_duration(d).unwrap().ticks(), 0);
pub const fn checked_add_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u32, O_NOM, O_DENOM>
) -> Option<Instant<u32, NOM, DENOM>>
pub const fn checked_add_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u32, O_NOM, O_DENOM>
) -> Option<Instant<u32, NOM, DENOM>>
Add a Duration
to an Instant
while checking for overflow.
let i = Instant::<u32, 1, 1_000>::from_ticks(1);
let d = Duration::<u32, 1, 1_000>::from_ticks(1);
assert_eq!(i.checked_add_duration(d).unwrap().ticks(), 2);
impl<const NOM: u32, const DENOM: u32> Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Instant<u64, NOM, DENOM>
pub const fn from_ticks(ticks: u64) -> Instant<u64, NOM, DENOM>
pub const fn from_ticks(ticks: u64) -> Instant<u64, NOM, DENOM>
Create an Instant
from a ticks value.
let _i = Instant::<u64, 1, 1_000>::from_ticks(1);
pub const fn ticks(&self) -> u64
pub const fn ticks(&self) -> u64
Extract the ticks from an Instant
.
let i = Instant::<u64, 1, 1_000>::from_ticks(234);
assert_eq!(i.ticks(), 234);
pub const fn const_cmp(self, other: Instant<u64, NOM, DENOM>) -> Ordering
pub const fn const_cmp(self, other: Instant<u64, NOM, DENOM>) -> Ordering
Const comparison of Instant
s.
let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);
assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);
pub const fn duration_since_epoch(self) -> Duration<u64, NOM, DENOM>
pub const fn duration_since_epoch(self) -> Duration<u64, NOM, DENOM>
Duration between since the start of the Instant
. This assumes an instant which
won’t wrap within the execution of the program.
let i = Instant::<u64, 1, 1_000>::from_ticks(11);
assert_eq!(i.duration_since_epoch().ticks(), 11);
pub const fn checked_duration_since(
self,
other: Instant<u64, NOM, DENOM>
) -> Option<Duration<u64, NOM, DENOM>>
pub const fn checked_duration_since(
self,
other: Instant<u64, NOM, DENOM>
) -> Option<Duration<u64, NOM, DENOM>>
Duration between Instant
s.
let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);
assert_eq!(i1.checked_duration_since(i2), None);
assert_eq!(i2.checked_duration_since(i1).unwrap().ticks(), 1);
pub const fn checked_sub_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u64, O_NOM, O_DENOM>
) -> Option<Instant<u64, NOM, DENOM>>
pub const fn checked_sub_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u64, O_NOM, O_DENOM>
) -> Option<Instant<u64, NOM, DENOM>>
Subtract a Duration
from an Instant
while checking for overflow.
let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);
assert_eq!(i.checked_sub_duration(d).unwrap().ticks(), 0);
pub const fn checked_add_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u64, O_NOM, O_DENOM>
) -> Option<Instant<u64, NOM, DENOM>>
pub const fn checked_add_duration<const O_NOM: u32, const O_DENOM: u32>(
self,
other: Duration<u64, O_NOM, O_DENOM>
) -> Option<Instant<u64, NOM, DENOM>>
Add a Duration
to an Instant
while checking for overflow.
let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);
assert_eq!(i.checked_add_duration(d).unwrap().ticks(), 2);
Trait Implementations
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
fn add_assign(&mut self, other: Duration<u32, NOM, DENOM>)
fn add_assign(&mut self, other: Duration<u32, NOM, DENOM>)
Performs the +=
operation. Read more
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
fn add_assign(&mut self, other: Duration<u32, NOM, DENOM>)
fn add_assign(&mut self, other: Duration<u32, NOM, DENOM>)
Performs the +=
operation. Read more
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
fn add_assign(&mut self, other: Duration<u64, NOM, DENOM>)
fn add_assign(&mut self, other: Duration<u64, NOM, DENOM>)
Performs the +=
operation. Read more
impl<const NOM: u32, const DENOM: u32> Ord for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Ord for Instant<u32, NOM, DENOM>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
impl<const NOM: u32, const DENOM: u32> Ord for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Ord for Instant<u64, NOM, DENOM>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
impl<const NOM: u32, const DENOM: u32> PartialEq<Instant<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialEq<Instant<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialEq<Instant<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialEq<Instant<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialOrd<Instant<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialOrd<Instant<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
fn partial_cmp(&self, other: &Instant<u32, NOM, DENOM>) -> Option<Ordering>
fn partial_cmp(&self, other: &Instant<u32, NOM, DENOM>) -> 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
impl<const NOM: u32, const DENOM: u32> PartialOrd<Instant<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> PartialOrd<Instant<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
fn partial_cmp(&self, other: &Instant<u64, NOM, DENOM>) -> Option<Ordering>
fn partial_cmp(&self, other: &Instant<u64, NOM, DENOM>) -> 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
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u32, NOM, DENOM>> for Instant<u32, NOM, DENOM>
fn sub_assign(&mut self, other: Duration<u32, NOM, DENOM>)
fn sub_assign(&mut self, other: Duration<u32, NOM, DENOM>)
Performs the -=
operation. Read more
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
fn sub_assign(&mut self, other: Duration<u32, NOM, DENOM>)
fn sub_assign(&mut self, other: Duration<u32, NOM, DENOM>)
Performs the -=
operation. Read more
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
fn sub_assign(&mut self, other: Duration<u64, NOM, DENOM>)
fn sub_assign(&mut self, other: Duration<u64, NOM, DENOM>)
Performs the -=
operation. Read more
impl<T, const NOM: u32, const DENOM: u32> Copy for Instant<T, NOM, DENOM> where
T: Copy,
impl<const NOM: u32, const DENOM: u32> Eq for Instant<u32, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Eq for Instant<u64, NOM, DENOM>
Auto Trait Implementations
impl<T, const NOM: u32, const DENOM: u32> RefUnwindSafe for Instant<T, NOM, DENOM> where
T: RefUnwindSafe,
impl<T, const NOM: u32, const DENOM: u32> Send for Instant<T, NOM, DENOM> where
T: Send,
impl<T, const NOM: u32, const DENOM: u32> Sync for Instant<T, NOM, DENOM> where
T: Sync,
impl<T, const NOM: u32, const DENOM: u32> Unpin for Instant<T, NOM, DENOM> where
T: Unpin,
impl<T, const NOM: u32, const DENOM: u32> UnwindSafe for Instant<T, NOM, DENOM> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
sourcefn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
sourceimpl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
sourcefn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.