2021-05-12 10:46:18 -04:00
|
|
|
//! Time units
|
|
|
|
|
|
|
|
/// Hertz
|
2021-05-18 21:52:34 -03:00
|
|
|
#[derive(PartialEq, PartialOrd, Clone, Copy, Debug, Eq)]
|
2021-05-12 10:46:18 -04:00
|
|
|
pub struct Hertz(pub u32);
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
impl Hertz {
|
|
|
|
pub fn hz(hertz: u32) -> Self {
|
|
|
|
Self(hertz)
|
2021-05-12 10:46:18 -04:00
|
|
|
}
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
pub fn khz(kilohertz: u32) -> Self {
|
|
|
|
Self(kilohertz * 1_000)
|
2021-05-12 10:46:18 -04:00
|
|
|
}
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
pub fn mhz(megahertz: u32) -> Self {
|
|
|
|
Self(megahertz * 1_000_000)
|
2021-05-12 10:46:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
/// This is a convenience shortcut for [`Hertz::hz`]
|
|
|
|
pub fn hz(hertz: u32) -> Hertz {
|
|
|
|
Hertz::hz(hertz)
|
2021-05-12 10:46:18 -04:00
|
|
|
}
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
/// This is a convenience shortcut for [`Hertz::khz`]
|
|
|
|
pub fn khz(kilohertz: u32) -> Hertz {
|
|
|
|
Hertz::khz(kilohertz)
|
2021-05-12 10:46:18 -04:00
|
|
|
}
|
|
|
|
|
2022-07-10 17:36:10 -05:00
|
|
|
/// This is a convenience shortcut for [`Hertz::mhz`]
|
|
|
|
pub fn mhz(megahertz: u32) -> Hertz {
|
|
|
|
Hertz::mhz(megahertz)
|
2021-05-14 10:11:43 -04:00
|
|
|
}
|