pub struct Uptime {
pub awake: Duration,
pub elapsed: Duration,
}Expand description
A moment read on both monotonic clocks at once.
The fields are counted from a fixed point in the past — the machine’s boot where the platform
offers it, otherwise the first reading in this process — so a single Uptime is only
meaningful next to another one. Keep the reading you started from and compare.
use qframe::uptime::Uptime;
let started = Uptime::now();
// ... the application runs, and the machine may be suspended in between ...
let now = Uptime::now();
let worked = now.awake.saturating_sub(started.awake);
let asleep = now.suspended_since(&started);
assert_eq!(asleep, std::time::Duration::ZERO, "nothing slept in a test");
assert!(worked < std::time::Duration::from_secs(1));Fields§
§awake: DurationTime counted by the clock that stops while the machine is asleep.
elapsed: DurationTime counted by the clock that keeps going while the machine is asleep. Equal to awake
on a platform with no second clock; see Uptime::detects_suspend.
Implementations§
Source§impl Uptime
impl Uptime
Sourcepub fn suspended_since(&self, earlier: &Self) -> Duration
pub fn suspended_since(&self, earlier: &Self) -> Duration
How long the machine was suspended between earlier and this reading.
Zero when the readings are in the wrong order, and zero on a platform that cannot tell sleep apart.
Sourcepub fn detects_suspend() -> bool
pub fn detects_suspend() -> bool
Whether this platform has a second clock, so Uptime::suspended_since can report sleep
at all. true on Linux and Android, false everywhere else.
Trait Implementations§
impl Copy for Uptime
impl Eq for Uptime
Source§impl Ord for Uptime
impl Ord for Uptime
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Uptime
impl PartialOrd for Uptime
impl StructuralPartialEq for Uptime
Auto Trait Implementations§
impl Freeze for Uptime
impl RefUnwindSafe for Uptime
impl Send for Uptime
impl Sync for Uptime
impl Unpin for Uptime
impl UnsafeUnpin for Uptime
impl UnwindSafe for Uptime
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more