#[repr(transparent)]pub struct Tick(pub u64);Expand description
An instant or duration in cycles of the PC’s 315/22 MHz crystal.
One cycle is exactly 22/315 microseconds. PIT input cycles span 12 ticks;
an OPL native sample spans 288 ticks. Integer conversions round down to whole ticks.
For repeated charges, use TickAccumulator to retain the fractional part.
Arithmetic panics on overflow or subtraction below zero in all build profiles.
Tuple Fields§
§0: u64Implementations§
Source§impl Tick
impl Tick
Sourcepub const HZ_NUMERATOR: u64 = 315_000_000
pub const HZ_NUMERATOR: u64 = 315_000_000
Numerator of the crystal frequency in hertz.
Sourcepub const HZ_DENOMINATOR: u64 = 22
pub const HZ_DENOMINATOR: u64 = 22
Denominator of the crystal frequency in hertz.
Sourcepub const fn from_micros(micros: u64) -> Tick
pub const fn from_micros(micros: u64) -> Tick
Sourcepub const fn from_nanos(nanos: u64) -> Tick
pub const fn from_nanos(nanos: u64) -> Tick
Convert integer nanoseconds, rounding down.
Sourcepub const fn from_duration(duration: Duration) -> Tick
pub const fn from_duration(duration: Duration) -> Tick
Sourcepub const fn checked_from_duration(duration: Duration) -> Option<Tick>
pub const fn checked_from_duration(duration: Duration) -> Option<Tick>
Convert a duration, returning None on overflow.
Sourcepub fn from_secs_f64(seconds: f64) -> Tick
pub fn from_secs_f64(seconds: f64) -> Tick
Convert approximate floating-point seconds, rounding to the nearest tick.
Rounding makes Tick::from_secs_f64(t.as_secs_f64()) == t despite float error.
Prefer Self::from_duration when exact integer conversion matters.
§Panics
Panics for negative, non-finite or out-of-range input.
Sourcepub const fn as_duration(self) -> Duration
pub const fn as_duration(self) -> Duration
Convert to a duration, rounding down to whole nanoseconds.
Sourcepub fn as_secs_f64(self) -> f64
pub fn as_secs_f64(self) -> f64
Approximate seconds, for display or compatibility with older clocks.
Sourcepub fn as_nanos_f64(self) -> f64
pub fn as_nanos_f64(self) -> f64
Approximate nanoseconds, for compatibility with older device interfaces.
Sourcepub const fn checked_add(self, rhs: Tick) -> Option<Tick>
pub const fn checked_add(self, rhs: Tick) -> Option<Tick>
Add a duration, returning None on overflow.
Sourcepub const fn checked_sub(self, rhs: Tick) -> Option<Tick>
pub const fn checked_sub(self, rhs: Tick) -> Option<Tick>
Subtract an instant or duration, returning None if rhs is greater.
Trait Implementations§
Source§impl AddAssign for Tick
impl AddAssign for Tick
Source§fn add_assign(&mut self, rhs: Tick)
fn add_assign(&mut self, rhs: Tick)
+= operation. Read more