From 4863f88d02ca1821eac534729fb9ba347a8c6726 Mon Sep 17 00:00:00 2001 From: Sebastian Goll Date: Thu, 13 Apr 2023 00:04:44 +0200 Subject: [PATCH] Make Hertz constructors `const` This allows them to be used in constant values. --- embassy-stm32/src/time.rs | 12 ++++++------ 1 file 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}; pub struct Hertz(pub u32); impl Hertz { - pub fn hz(hertz: u32) -> Self { + pub const fn hz(hertz: u32) -> Self { Self(hertz) } - pub fn khz(kilohertz: u32) -> Self { + pub const fn khz(kilohertz: u32) -> Self { Self(kilohertz * 1_000) } - pub fn mhz(megahertz: u32) -> Self { + pub const fn mhz(megahertz: u32) -> Self { Self(megahertz * 1_000_000) } } /// This is a convenience shortcut for [`Hertz::hz`] -pub fn hz(hertz: u32) -> Hertz { +pub const fn hz(hertz: u32) -> Hertz { Hertz::hz(hertz) } /// This is a convenience shortcut for [`Hertz::khz`] -pub fn khz(kilohertz: u32) -> Hertz { +pub const fn khz(kilohertz: u32) -> Hertz { Hertz::khz(kilohertz) } /// This is a convenience shortcut for [`Hertz::mhz`] -pub fn mhz(megahertz: u32) -> Hertz { +pub const fn mhz(megahertz: u32) -> Hertz { Hertz::mhz(megahertz) }