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