pub struct Instant(/* private fields */);
Expand description
Represents time from the start of the simulation
Instant
is for representing the current running clock. It uses a
duration to represent the time from simulation start, and is monotonic.
Implementations§
source§impl Instant
impl Instant
sourcepub const FOREVER: Self = _
pub const FOREVER: Self = _
An Instant
representing the greatest possible time (t = Femtos::MAX
)
sourcepub const fn as_duration(self) -> Duration
pub const fn as_duration(self) -> Duration
Returns a Duration
equivalent to the amount of time elapsed since the earliest
possible time (t = 0).
sourcepub fn duration_since(self, other: Self) -> Duration
pub fn duration_since(self, other: Self) -> Duration
Returns the Duration
that has elapsed between this Instant
and other
.
§Examples
use femtos::{Instant, Duration};
let now = Instant::START + Duration::from_secs(1);
assert_eq!(now.duration_since(Instant::START), Duration::from_secs(1));
sourcepub const fn checked_add(self, duration: Duration) -> Option<Self>
pub const fn checked_add(self, duration: Duration) -> Option<Self>
Checked Instant
addition. Computes self + duration
, returning None
if an overflow occured.
§Examples
use femtos::{Instant, Duration, Femtos};
assert_eq!(
Instant::START.checked_add(Duration::from_secs(1)).map(|i| i.as_duration()),
Some(Duration::from_secs(1))
);
assert_eq!(Instant::FOREVER.checked_add(Duration::from_femtos(1)), None);
sourcepub const fn checked_sub(self, duration: Duration) -> Option<Self>
pub const fn checked_sub(self, duration: Duration) -> Option<Self>
Checked Instant
subtraction. Computes self - duration
, returning None
if an overflow occured.
§Examples
use femtos::{Instant, Duration, Femtos};
assert_eq!(
Instant::FOREVER.checked_sub(Duration::from_femtos(1)).map(|i| i.as_duration()),
Some(Duration::from_femtos(Femtos::MAX - 1))
);
assert_eq!(Instant::START.checked_sub(Duration::from_secs(1)), None);
Trait Implementations§
source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Performs the
+=
operation. Read moresource§impl Ord for Instant
impl Ord for Instant
source§impl PartialEq for Instant
impl PartialEq for Instant
source§impl PartialOrd for Instant
impl PartialOrd for Instant
1.0.0 · source§fn 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 moreimpl Copy for Instant
impl Eq for Instant
impl StructuralPartialEq for Instant
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnwindSafe for Instant
Blanket Implementations§
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
Mutably borrows from an owned value. Read more