1#[derive(PartialEq, PartialOrd, Clone, Copy)]
3pub struct Bps(pub u32);
4
5#[derive(PartialEq, PartialOrd, Clone, Copy)]
6pub struct Hertz(pub u32);
7
8#[derive(PartialEq, PartialOrd, Clone, Copy)]
9pub struct KiloHertz(pub u32);
10
11#[derive(PartialEq, PartialOrd, Clone, Copy)]
12pub struct MegaHertz(pub u32);
13
14pub trait U32Ext {
16 fn bps(self) -> Bps;
18
19 fn hz(self) -> Hertz;
21
22 fn khz(self) -> KiloHertz;
24
25 fn mhz(self) -> MegaHertz;
27}
28
29impl U32Ext for u32 {
30 fn bps(self) -> Bps {
31 Bps(self)
32 }
33
34 fn hz(self) -> Hertz {
35 Hertz(self)
36 }
37
38 fn khz(self) -> KiloHertz {
39 KiloHertz(self)
40 }
41
42 fn mhz(self) -> MegaHertz {
43 MegaHertz(self)
44 }
45}
46
47impl Into<Hertz> for KiloHertz {
48 fn into(self) -> Hertz {
49 Hertz(self.0 * 1_000)
50 }
51}
52
53impl Into<Hertz> for MegaHertz {
54 fn into(self) -> Hertz {
55 Hertz(self.0 * 1_000_000)
56 }
57}
58
59impl Into<KiloHertz> for MegaHertz {
60 fn into(self) -> KiloHertz {
61 KiloHertz(self.0 * 1_000)
62 }
63}