pub struct Instant { /* private fields */ }
Expand description
An Instant in time. Instants should be always increasing and are generally obtainable through the operating system time driver.
Implementations§
Source§impl Instant
impl Instant
Sourcepub const fn duration_since(&self, earlier: Instant) -> Option<Duration>
pub const fn duration_since(&self, earlier: Instant) -> Option<Duration>
Returns the Duration
between this Instant
and the give one if, and only if,
the given one is earlier than this, otherwise returns None.
§Examples
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let begin = Time::now();
std::thread::sleep(core::time::Duration::from_millis(1));
let end = Time::now();
assert!(end.duration_since(begin).unwrap() > Duration::ZERO);
assert_eq!(begin.duration_since(end), None);
Sourcepub fn checked_add(self, rhs: Duration) -> Option<Instant>
pub fn checked_add(self, rhs: Duration) -> Option<Instant>
Adds one Duration
to self, returning a new Instant
or None in the event of an overflow.
§Examples
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let now = Time::now();
assert!(now.checked_add(Duration::from_secs(1)).unwrap() > now);
assert_eq!(now.checked_add(Duration::MAX), None);
Sourcepub fn checked_sub(&self, rhs: Duration) -> Option<Instant>
pub fn checked_sub(&self, rhs: Duration) -> Option<Instant>
Subs one Duration
from self, returning a new Instant
or None in the event of an underflow.
§Examples
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let begin = Time::now();
std::thread::sleep(core::time::Duration::from_millis(1));
let end = Time::now();
assert!(end.checked_sub(Duration::from_millis(1)).unwrap() < end);
assert_eq!(end.checked_sub(Duration::MAX), None);
Trait Implementations§
Source§impl Add<Duration> for Instant
impl Add<Duration> for Instant
Source§fn add(self, rhs: Duration) -> <Instant as Add<Duration>>::Output
fn add(self, rhs: Duration) -> <Instant as Add<Duration>>::Output
§Panics
This function may panic if the resulting instant overflows. See Instant::checked_add
for a version
without panic.
§Examples
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let now = Time::now();
assert!(now + Duration::from_secs(1) > now);
ⓘ
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let now = Time::now();
let _ = now + Duration::MAX;
Source§impl Ord for Instant
impl Ord for Instant
Source§impl PartialOrd for Instant
impl PartialOrd for Instant
Source§impl Sub<Duration> for Instant
impl Sub<Duration> for Instant
Source§fn sub(self, rhs: Duration) -> <Instant as Sub<Duration>>::Output
fn sub(self, rhs: Duration) -> <Instant as Sub<Duration>>::Output
§Panics
This function may panic if the resulting instant underflows. See Instant::checked_sub
for a
version without panic.
§Examples
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let begin = Time::now();
std::thread::sleep(core::time::Duration::from_millis(1));
let end = Time::now();
assert!(end - Duration::from_millis(1) < end);
ⓘ
use veecle_osal_api::time::{Duration, Instant, TimeAbstraction};
use veecle_osal_std::time::Time;
let now = Time::now();
let _ = now - Duration::MAX;
impl 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