Trait Frequencies
pub trait Frequencies: Copy + Mul<Freq, Output = Duration> {
// Provided methods
fn GHz(self) -> Duration { ... }
fn MHz(self) -> Duration { ... }
fn kHz(self) -> Duration { ... }
fn Hz(self) -> Duration { ... }
}
Expand description
A trait to automatically convert some primitives to an approximate frequency as a duration.
Note on Precision: The conversion is rounded to the closest nanosecond because Duration
has nanosecond precision. Frequencies greater than 1 GHz (i.e., periods less than 1 nanosecond)
cannot be accurately represented. Such high frequencies will result in a Duration
of zero
or an inaccurate, truncated nanosecond value.
use hifitime::prelude::*;
assert_eq!(1.Hz(), 1.seconds());
assert_eq!(10.Hz(), 0.1.seconds());
assert_eq!(100.Hz(), 0.01.seconds());
assert_eq!(1.MHz(), 1.microseconds());
assert_eq!(250.MHz(), 4.nanoseconds());
assert_eq!(1.GHz(), 1.nanoseconds());
// LIMITATIONS
assert_eq!(240.MHz(), 4.nanoseconds()); // 240 MHz is actually 4.1666.. nanoseconds, not 4 exactly!
assert_eq!(10.GHz(), 0.nanoseconds()); // As 10 GHz corresponds to 0.1 ns, it's truncated to 0 ns.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.