Make Hertz constructors const
This allows them to be used in constant values.
This commit is contained in:
parent
ba8cafb20c
commit
4863f88d02
1 changed files with 6 additions and 6 deletions
|
@ -8,31 +8,31 @@ use core::ops::{Div, Mul};
|
||||||
pub struct Hertz(pub u32);
|
pub struct Hertz(pub u32);
|
||||||
|
|
||||||
impl Hertz {
|
impl Hertz {
|
||||||
pub fn hz(hertz: u32) -> Self {
|
pub const fn hz(hertz: u32) -> Self {
|
||||||
Self(hertz)
|
Self(hertz)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn khz(kilohertz: u32) -> Self {
|
pub const fn khz(kilohertz: u32) -> Self {
|
||||||
Self(kilohertz * 1_000)
|
Self(kilohertz * 1_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mhz(megahertz: u32) -> Self {
|
pub const fn mhz(megahertz: u32) -> Self {
|
||||||
Self(megahertz * 1_000_000)
|
Self(megahertz * 1_000_000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is a convenience shortcut for [`Hertz::hz`]
|
/// This is a convenience shortcut for [`Hertz::hz`]
|
||||||
pub fn hz(hertz: u32) -> Hertz {
|
pub const fn hz(hertz: u32) -> Hertz {
|
||||||
Hertz::hz(hertz)
|
Hertz::hz(hertz)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is a convenience shortcut for [`Hertz::khz`]
|
/// This is a convenience shortcut for [`Hertz::khz`]
|
||||||
pub fn khz(kilohertz: u32) -> Hertz {
|
pub const fn khz(kilohertz: u32) -> Hertz {
|
||||||
Hertz::khz(kilohertz)
|
Hertz::khz(kilohertz)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is a convenience shortcut for [`Hertz::mhz`]
|
/// This is a convenience shortcut for [`Hertz::mhz`]
|
||||||
pub fn mhz(megahertz: u32) -> Hertz {
|
pub const fn mhz(megahertz: u32) -> Hertz {
|
||||||
Hertz::mhz(megahertz)
|
Hertz::mhz(megahertz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue