1#![allow(clippy::from_over_into)]
6
7#[derive(PartialEq, PartialOrd, Clone, Copy)]
9pub struct Bps(pub u32);
10
11#[derive(PartialEq, PartialOrd, Clone, Copy)]
12pub struct Hertz(pub u32);
13
14#[derive(PartialEq, PartialOrd, Clone, Copy)]
15pub struct KiloHertz(pub u32);
16
17#[derive(PartialEq, PartialOrd, Clone, Copy)]
18pub struct MegaHertz(pub u32);
19
20pub trait U32Ext {
22 fn bps(self) -> Bps;
24
25 fn hz(self) -> Hertz;
27
28 fn khz(self) -> KiloHertz;
30
31 fn mhz(self) -> MegaHertz;
33
34 fn ms(self) -> MilliSeconds;
36}
37
38impl U32Ext for u32 {
39 fn bps(self) -> Bps {
40 Bps(self)
41 }
42
43 fn hz(self) -> Hertz {
44 Hertz(self)
45 }
46
47 fn khz(self) -> KiloHertz {
48 KiloHertz(self)
49 }
50
51 fn mhz(self) -> MegaHertz {
52 MegaHertz(self)
53 }
54
55 fn ms(self) -> MilliSeconds {
56 MilliSeconds(self)
57 }
58}
59
60impl Into<Hertz> for KiloHertz {
61 fn into(self) -> Hertz {
62 Hertz(self.0 * 1_000)
63 }
64}
65
66impl Into<Hertz> for MegaHertz {
67 fn into(self) -> Hertz {
68 Hertz(self.0 * 1_000_000)
69 }
70}
71
72impl Into<KiloHertz> for MegaHertz {
73 fn into(self) -> KiloHertz {
74 KiloHertz(self.0 * 1_000)
75 }
76}
77
78#[derive(PartialEq, PartialOrd, Clone, Copy)]
80pub struct MilliSeconds(pub u32);