pub struct RefreshRate { /* private fields */ }Expand description
A display refresh rate expressed as an exact rational number (numerator/denominator in Hz).
Integer rates (60 Hz, 120 Hz, etc.) use denom = 1. NTSC-derived fractional rates use
denom = 1001 (e.g. 60000/1001 ≈ 59.94 Hz, 24000/1001 ≈ 23.976 Hz).
Always stored in lowest terms: all constructors (including Deserialize) apply GCD
reduction, so ==, Hash, and Ord are consistent and a given rate has exactly one
canonical representation.
Use RefreshRate::integral for integer rates and RefreshRate::fractional for all
others. From<u32> and From<u16> are implemented as integral conversions, so
integer literals work wherever impl Into<RefreshRate> is accepted.
Implementations§
Source§impl RefreshRate
impl RefreshRate
Sourcepub fn integral(hz: u32) -> Self
pub fn integral(hz: u32) -> Self
Constructs an integer refresh rate (e.g. RefreshRate::integral(60) → 60/1).
Sourcepub fn fractional(numer: u32, denom: u32) -> Self
pub fn fractional(numer: u32, denom: u32) -> Self
Constructs an exact rational refresh rate, reduced to lowest terms.
§Panics
Panics if denom is zero.
Sourcepub fn from_ratio(numer: u64, denom: u64) -> Option<Self>
pub fn from_ratio(numer: u64, denom: u64) -> Option<Self>
Constructs a refresh rate from a numer/denom ratio in Hz, reduced to lowest terms.
Useful when the rate is computed from intermediate values that exceed u32, such as
pixel_clock_hz / (h_total × v_total) for detailed-timing descriptors. Reduces in
u64 then narrows to u32.
Returns None if denom is zero or if the reduced fraction does not fit in u32.
use display_types::RefreshRate;
// NTSC-style fractional rate computed from a large numerator and denominator.
let r = RefreshRate::from_ratio(60_000_000, 1_001_000).unwrap();
assert_eq!(r, RefreshRate::fractional(60_000, 1_001));Trait Implementations§
Source§impl Clone for RefreshRate
impl Clone for RefreshRate
Source§fn clone(&self) -> RefreshRate
fn clone(&self) -> RefreshRate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RefreshRate
impl Debug for RefreshRate
Source§impl Display for RefreshRate
impl Display for RefreshRate
Source§impl From<u16> for RefreshRate
impl From<u16> for RefreshRate
Source§impl From<u32> for RefreshRate
impl From<u32> for RefreshRate
Source§impl Hash for RefreshRate
impl Hash for RefreshRate
Source§impl Ord for RefreshRate
impl Ord for RefreshRate
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for RefreshRate
impl PartialEq for RefreshRate
Source§fn eq(&self, other: &RefreshRate) -> bool
fn eq(&self, other: &RefreshRate) -> bool
self and other values to be equal, and is used by ==.