pub struct Timescale<const SCALE: u64>(/* private fields */);Expand description
A timestamp representing the presentation time in a given scale. ex. 1000 for milliseconds.
All timestamps within a track are relative, so zero for one track is not zero for another. Values are constrained to fit within a QUIC VarInt (2^62) so they can be encoded and decoded easily.
This is std::time::Instant and std::time::Duration merged into one type for simplicity.
Implementations§
Source§impl<const SCALE: u64> Timescale<SCALE>
impl<const SCALE: u64> Timescale<SCALE>
pub const fn new(value: u32) -> Self
pub const fn new_u64(value: u64) -> Result<Self, TimeOverflow>
Sourcepub const fn from_secs(seconds: u64) -> Result<Self, TimeOverflow>
pub const fn from_secs(seconds: u64) -> Result<Self, TimeOverflow>
Convert a number of seconds to a timestamp, returning an error if the timestamp would overflow.
pub const fn from_secs_unchecked(seconds: u64) -> Self
Sourcepub const fn from_millis(millis: u64) -> Result<Self, TimeOverflow>
pub const fn from_millis(millis: u64) -> Result<Self, TimeOverflow>
Convert a number of milliseconds to a timestamp, returning an error if the timestamp would overflow.
pub const fn from_millis_unchecked(millis: u64) -> Self
pub const fn from_micros(micros: u64) -> Result<Self, TimeOverflow>
pub const fn from_micros_unchecked(micros: u64) -> Self
pub const fn from_nanos(nanos: u64) -> Result<Self, TimeOverflow>
pub const fn from_nanos_unchecked(nanos: u64) -> Self
pub const fn from_scale(value: u64, scale: u64) -> Result<Self, TimeOverflow>
pub const fn from_scale_u128( value: u128, scale: u64, ) -> Result<Self, TimeOverflow>
pub const fn from_scale_unchecked(value: u64, scale: u64) -> Self
pub const fn as_scale(self, scale: u64) -> u128
pub const fn checked_add(self, rhs: Self) -> Result<Self, TimeOverflow>
pub const fn checked_sub(self, rhs: Self) -> Result<Self, TimeOverflow>
pub const fn is_zero(self) -> bool
pub fn now() -> Self
Sourcepub const fn convert<const NEW_SCALE: u64>(
self,
) -> Result<Timescale<NEW_SCALE>, TimeOverflow>
pub const fn convert<const NEW_SCALE: u64>( self, ) -> Result<Timescale<NEW_SCALE>, TimeOverflow>
Convert this timestamp to a different scale.
This allows converting between different TimeScale types, for example from milliseconds to microseconds. Note that converting to a coarser scale may lose precision due to integer division.
Trait Implementations§
Source§impl<const SCALE: u64> AddAssign for Timescale<SCALE>
impl<const SCALE: u64> AddAssign for Timescale<SCALE>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<const SCALE: u64> Ord for Timescale<SCALE>
impl<const SCALE: u64> Ord for Timescale<SCALE>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const SCALE: u64> PartialOrd for Timescale<SCALE>
impl<const SCALE: u64> PartialOrd for Timescale<SCALE>
Source§impl<const SCALE: u64> SubAssign for Timescale<SCALE>
impl<const SCALE: u64> SubAssign for Timescale<SCALE>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more