aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Goll <[email protected]>2023-04-13 00:04:44 +0200
committerSebastian Goll <[email protected]>2023-04-13 00:06:14 +0200
commit4863f88d02ca1821eac534729fb9ba347a8c6726 (patch)
treedc283068d72f8e14dcc14aeaff314c23f8827f0e
parentba8cafb20c2458a2016c7db3efd91d718f1a91b6 (diff)
Make Hertz constructors `const`
This allows them to be used in constant values.
-rw-r--r--embassy-stm32/src/time.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/embassy-stm32/src/time.rs b/embassy-stm32/src/time.rs
index f08abe331..604503e61 100644
--- a/embassy-stm32/src/time.rs
+++ b/embassy-stm32/src/time.rs
@@ -8,31 +8,31 @@ use core::ops::{Div, Mul};
8pub struct Hertz(pub u32); 8pub struct Hertz(pub u32);
9 9
10impl Hertz { 10impl Hertz {
11 pub fn hz(hertz: u32) -> Self { 11 pub const fn hz(hertz: u32) -> Self {
12 Self(hertz) 12 Self(hertz)
13 } 13 }
14 14
15 pub fn khz(kilohertz: u32) -> Self { 15 pub const fn khz(kilohertz: u32) -> Self {
16 Self(kilohertz * 1_000) 16 Self(kilohertz * 1_000)
17 } 17 }
18 18
19 pub fn mhz(megahertz: u32) -> Self { 19 pub const fn mhz(megahertz: u32) -> Self {
20 Self(megahertz * 1_000_000) 20 Self(megahertz * 1_000_000)
21 } 21 }
22} 22}
23 23
24/// This is a convenience shortcut for [`Hertz::hz`] 24/// This is a convenience shortcut for [`Hertz::hz`]
25pub fn hz(hertz: u32) -> Hertz { 25pub const fn hz(hertz: u32) -> Hertz {
26 Hertz::hz(hertz) 26 Hertz::hz(hertz)
27} 27}
28 28
29/// This is a convenience shortcut for [`Hertz::khz`] 29/// This is a convenience shortcut for [`Hertz::khz`]
30pub fn khz(kilohertz: u32) -> Hertz { 30pub const fn khz(kilohertz: u32) -> Hertz {
31 Hertz::khz(kilohertz) 31 Hertz::khz(kilohertz)
32} 32}
33 33
34/// This is a convenience shortcut for [`Hertz::mhz`] 34/// This is a convenience shortcut for [`Hertz::mhz`]
35pub fn mhz(megahertz: u32) -> Hertz { 35pub const fn mhz(megahertz: u32) -> Hertz {
36 Hertz::mhz(megahertz) 36 Hertz::mhz(megahertz)
37} 37}
38 38