pub struct Duration(/* private fields */);Expand description
A nonnegative span of time, stored as integer flicks.
Negative spans cannot be constructed. Use TimeOffset where a signed
displacement is meaningful, such as shifting a clip earlier. Durations add,
scale and subtract (panicking below zero, see Duration::checked_sub);
they share the tick unit and overflow behavior of Time.
Implementations§
Source§impl Duration
impl Duration
Sourcepub const fn from_ticks(ticks: u64) -> Self
pub const fn from_ticks(ticks: u64) -> Self
Constructs a duration 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 negative or nonfinite input or a rounded result beyond the
tick 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 negative, nonfinite or out-of-range input.
Sourcepub fn from_frame(frame: u64, rate: FrameRate) -> Self
pub fn from_frame(frame: u64, rate: FrameRate) -> Self
Returns the duration from the origin to a frame boundary, with the same
ceiling rule as Time::from_frame.
§Panics
Panics if the boundary cannot be represented as ticks.
Sourcepub fn checked_from_frame(frame: u64, rate: FrameRate) -> Option<Self>
pub fn checked_from_frame(frame: u64, rate: FrameRate) -> Option<Self>
Converts a frame boundary like Self::from_frame, returning None on overflow.
Sourcepub fn to_frame(self, rate: FrameRate) -> u64
pub fn to_frame(self, rate: FrameRate) -> u64
Returns the frame containing this span’s end, rounding down.
§Panics
Panics if the frame index is outside the unsigned 64-bit range.
Sourcepub fn checked_to_frame(self, rate: FrameRate) -> Option<u64>
pub fn checked_to_frame(self, rate: FrameRate) -> Option<u64>
Finds the frame count like Self::to_frame, returning None on overflow.
Sourcepub fn as_seconds(self) -> f64
pub fn as_seconds(self) -> f64
Converts to floating-point seconds for animation mathematics.
Sourcepub fn after_origin(self) -> Time
pub fn after_origin(self) -> Time
Returns the time point this far from the origin.
§Panics
Panics if the duration exceeds the signed tick range.
Sourcepub fn checked_offset(self) -> Option<TimeOffset>
pub fn checked_offset(self) -> Option<TimeOffset>
Returns the signed displacement of this duration, or None beyond the signed tick range.
Sourcepub fn offset(self) -> TimeOffset
pub fn offset(self) -> TimeOffset
Returns the signed displacement of this duration, for shifting time later.
§Panics
Panics if the duration exceeds the signed tick range; see Self::checked_offset.
Sourcepub fn checked_sub(self, other: Self) -> Option<Self>
pub fn checked_sub(self, other: Self) -> Option<Self>
Subtracts exactly, returning None when other is longer.
Sourcepub fn saturating_sub(self, other: Self) -> Self
pub fn saturating_sub(self, other: Self) -> Self
Subtracts, stopping at Self::ZERO when other is longer.
Sourcepub fn checked_mul(self, factor: u64) -> Option<Self>
pub fn checked_mul(self, factor: u64) -> Option<Self>
Multiplies ticks exactly, returning None on overflow.
Sourcepub fn try_mul(self, factor: f64) -> Result<Self, ValidationError>
pub fn try_mul(self, factor: f64) -> Result<Self, ValidationError>
Scales like the * f64 operator, reporting a negative or nonfinite factor and overflow.
Sourcepub fn try_div(self, divisor: f64) -> Result<Self, ValidationError>
pub fn try_div(self, divisor: f64) -> Result<Self, ValidationError>
Divides like the / f64 operator, reporting a negative, nonfinite or zero divisor and overflow.
Sourcepub fn try_ratio(self, divisor: Self) -> Result<f64, ValidationError>
pub fn try_ratio(self, divisor: Self) -> Result<f64, ValidationError>
Returns the dimensionless ratio, reporting a zero divisor.
Trait Implementations§
Source§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§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 moreimpl Copy for Duration
impl Eq for Duration
Source§impl Ord for Duration
impl Ord for Duration
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 Duration
impl PartialOrd for Duration
impl StructuralPartialEq for Duration
Source§impl SubAssign for Duration
impl SubAssign for Duration
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more