Merge pull request #61 from xoviat/us-delay

add us delays
This commit is contained in:
Dario Nieuwenhuis 2021-03-01 19:06:57 +01:00 committed by GitHub
commit 084b64053a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,10 @@ impl Duration {
self.ticks * 1000 / TICKS_PER_SECOND
}
pub const fn as_micros(&self) -> u64 {
self.ticks * 1_000_000 / TICKS_PER_SECOND
}
pub const fn from_ticks(ticks: u64) -> Duration {
Duration { ticks }
}
@ -38,6 +42,15 @@ impl Duration {
}
}
/*
NOTE: us delays may not be as accurate
*/
pub const fn from_micros(millis: u64) -> Duration {
Duration {
ticks: millis * TICKS_PER_SECOND / 1_000_000,
}
}
pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
self.ticks
.checked_add(rhs.ticks)