Skip to main content

RefreshRate

Struct RefreshRate 

Source
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

Source

pub fn integral(hz: u32) -> Self

Constructs an integer refresh rate (e.g. RefreshRate::integral(60) → 60/1).

Source

pub fn fractional(numer: u32, denom: u32) -> Self

Constructs an exact rational refresh rate, reduced to lowest terms.

§Panics

Panics if denom is zero.

Source

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));
Source

pub fn numer(self) -> u32

Numerator of the reduced fraction, in Hz.

Source

pub fn denom(self) -> u32

Denominator of the reduced fraction (1 for integer rates, 1001 for NTSC-derived rates).

Source

pub fn as_f64(self) -> f64

Returns the refresh rate as f64.

Trait Implementations§

Source§

impl Clone for RefreshRate

Source§

fn clone(&self) -> RefreshRate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RefreshRate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RefreshRate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<u16> for RefreshRate

Source§

fn from(hz: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for RefreshRate

Source§

fn from(hz: u32) -> Self

Converts to this type from the input type.
Source§

impl Hash for RefreshRate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RefreshRate

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for RefreshRate

Source§

fn eq(&self, other: &RefreshRate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RefreshRate

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for RefreshRate

Source§

impl Eq for RefreshRate

Source§

impl StructuralPartialEq for RefreshRate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ExtensionData for T
where T: Any + Debug + Send + Sync,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns self as &dyn Any to enable downcasting.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.