Add from_hz function for Duration.

This commit is contained in:
Caleb Jamison 2023-02-09 19:22:06 -05:00
parent e1a0df7d46
commit a4371e9544

View File

@ -81,6 +81,11 @@ impl Duration {
} }
} }
/// Creates a duration corresponding to the specified Hz.
pub const fn from_hz(hz: u64) -> Duration {
Duration { ticks: TICK_HZ / hz }
}
/// Adds one Duration to another, returning a new Duration or None in the event of an overflow. /// Adds one Duration to another, returning a new Duration or None in the event of an overflow.
pub fn checked_add(self, rhs: Duration) -> Option<Duration> { pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks }) self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks })