pub struct Time(/* private fields */);Expand description
A signed time point or duration, stored as integer flicks.
Comparisons and frame conversion use integers. Floating-point seconds are intended for animation mathematics, not interval membership checks. Arithmetic panics on overflow, independently of the build profile.
Implementations§
Source§impl Time
impl Time
Sourcepub const fn from_ticks(ticks: i64) -> Self
pub const fn from_ticks(ticks: i64) -> Self
Constructs time without losing integer tick precision.
Sourcepub fn from_seconds(seconds: f64) -> Self
pub fn from_seconds(seconds: f64) -> Self
Rounds seconds to the nearest tick; halfway cases round away from zero.
§Panics
Panics for nonfinite input or a rounded result outside the signed range.
Sourcepub fn from_frame(frame: i64, rate: FrameRate) -> Self
pub fn from_frame(frame: i64, rate: FrameRate) -> Self
Returns the first tick at or after the exact rational frame boundary.
Common integer and NTSC rates have exact tick boundaries. Other rates
round toward positive infinity by less than one tick, including before
zero. Compute each boundary directly; multiplying a rounded frame duration
would accumulate drift. Frame indices round-trip through Self::to_frame
when the rate does not exceed one frame per tick.
§Panics
Panics if the boundary cannot be represented as signed ticks.
Sourcepub fn checked_from_frame(frame: i64, rate: FrameRate) -> Option<Self>
pub fn checked_from_frame(frame: i64, rate: FrameRate) -> Option<Self>
Converts a frame boundary with the same ceiling rule as from_frame. Returns None instead of panicking when signed ticks would overflow.
Sourcepub fn to_frame(self, rate: FrameRate) -> i64
pub fn to_frame(self, rate: FrameRate) -> i64
Returns the containing frame, rounding toward negative infinity.
§Panics
Panics if the frame index is outside the signed 64-bit range.
Sourcepub fn checked_to_frame(self, rate: FrameRate) -> Option<i64>
pub fn checked_to_frame(self, rate: FrameRate) -> Option<i64>
Finds the containing frame using integer floor division. Returns None instead of panicking when the frame index would overflow.
Sourcepub fn as_seconds(self) -> f64
pub fn as_seconds(self) -> f64
Converts to floating-point seconds for animation mathematics.
Sourcepub fn checked_mul(self, factor: i64) -> Option<Self>
pub fn checked_mul(self, factor: i64) -> Option<Self>
Multiplies ticks exactly, returning None on signed overflow.
Trait Implementations§
Source§impl AddAssign for Time
impl AddAssign for Time
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read more