1use core::ops::{Div, Mul};
2
3#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)]
5pub struct Hertz(pub u32);
6
7impl Hertz {
8 pub const fn hz(hertz: u32) -> Self {
10 Self(hertz)
11 }
12
13 pub const fn khz(kilohertz: u32) -> Self {
15 Self(kilohertz * 1_000)
16 }
17
18 pub const fn mhz(megahertz: u32) -> Self {
20 Self(megahertz * 1_000_000)
21 }
22}
23
24impl From<Hertz> for u32 {
25 fn from(hz: Hertz) -> Self {
26 hz.0
27 }
28}
29
30pub const fn hz(hertz: u32) -> Hertz {
32 Hertz::hz(hertz)
33}
34
35pub const fn khz(kilohertz: u32) -> Hertz {
37 Hertz::khz(kilohertz)
38}
39
40pub const fn mhz(megahertz: u32) -> Hertz {
42 Hertz::mhz(megahertz)
43}
44
45impl Mul<u32> for Hertz {
46 type Output = Hertz;
47 fn mul(self, rhs: u32) -> Self::Output {
48 Hertz(self.0 * rhs)
49 }
50}
51
52impl Div<u32> for Hertz {
53 type Output = Hertz;
54 fn div(self, rhs: u32) -> Self::Output {
55 Hertz(self.0 / rhs)
56 }
57}
58
59impl Mul<u16> for Hertz {
60 type Output = Hertz;
61 fn mul(self, rhs: u16) -> Self::Output {
62 self * (rhs as u32)
63 }
64}
65
66impl Div<u16> for Hertz {
67 type Output = Hertz;
68 fn div(self, rhs: u16) -> Self::Output {
69 self / (rhs as u32)
70 }
71}
72
73impl Mul<u8> for Hertz {
74 type Output = Hertz;
75 fn mul(self, rhs: u8) -> Self::Output {
76 self * (rhs as u32)
77 }
78}
79
80impl Div<u8> for Hertz {
81 type Output = Hertz;
82 fn div(self, rhs: u8) -> Self::Output {
83 self / (rhs as u32)
84 }
85}
86
87impl Div<Hertz> for Hertz {
88 type Output = u32;
89 fn div(self, rhs: Hertz) -> Self::Output {
90 self.0 / rhs.0
91 }
92}