pub struct Time(/* private fields */);Expand description
A signed point on the timeline, stored as integer flicks since the origin.
Comparisons and frame conversion use integers. Floating-point seconds are
intended for animation mathematics, not interval membership checks.
Only meaningful operations exist: Time - Time is a signed TimeOffset,
and Time ± Duration or Time ± TimeOffset is a Time. 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;
see Self::try_from_seconds.
Sourcepub fn try_from_seconds(seconds: f64) -> Result<Self, ValidationError>
pub fn try_from_seconds(seconds: f64) -> Result<Self, ValidationError>
Rounds seconds like Self::from_seconds, reporting nonfinite or out-of-range input.
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 const fn since_origin(self) -> TimeOffset
pub const fn since_origin(self) -> TimeOffset
Returns the signed displacement from the origin to this time point.
Sourcepub fn duration_since(self, earlier: Self) -> Option<Duration>
pub fn duration_since(self, earlier: Self) -> Option<Duration>
Returns the span since an earlier time point, or None when earlier is later.
Sourcepub fn checked_add(self, span: Duration) -> Option<Self>
pub fn checked_add(self, span: Duration) -> Option<Self>
Adds a duration, returning None on signed overflow.
Sourcepub fn checked_sub(self, span: Duration) -> Option<Self>
pub fn checked_sub(self, span: Duration) -> Option<Self>
Subtracts a duration, returning None on signed overflow.
Trait Implementations§
Source§impl Add<TimeOffset> for Time
impl Add<TimeOffset> for Time
Source§impl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
Source§fn add_assign(&mut self, span: Duration)
fn add_assign(&mut self, span: Duration)
+= operation. Read moreSource§impl AddAssign<TimeOffset> for Time
impl AddAssign<TimeOffset> for Time
Source§fn add_assign(&mut self, offset: TimeOffset)
fn add_assign(&mut self, offset: TimeOffset)
+= operation. Read moreimpl Copy for Time
impl Eq for Time
Source§impl Ord for Time
impl Ord for Time
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Time
impl PartialOrd for Time
impl StructuralPartialEq for Time
Source§impl Sub for Time
impl Sub for Time
Source§type Output = TimeOffset
type Output = TimeOffset
- operator.Source§fn sub(self, other: Self) -> TimeOffset
fn sub(self, other: Self) -> TimeOffset
- operation. Read moreSource§impl Sub<TimeOffset> for Time
impl Sub<TimeOffset> for Time
Source§impl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
Source§fn sub_assign(&mut self, span: Duration)
fn sub_assign(&mut self, span: Duration)
-= operation. Read moreSource§impl SubAssign<TimeOffset> for Time
impl SubAssign<TimeOffset> for Time
Source§fn sub_assign(&mut self, offset: TimeOffset)
fn sub_assign(&mut self, offset: TimeOffset)
-= operation. Read more