Skip to main content

TimeRange

Struct TimeRange 

Source
pub struct TimeRange { /* private fields */ }
Expand description

A half-open time range [start, end) in a given Timebase.

Represents the extent of a detected event — for example, a fade-out → fade-in span. When start == end, the range is degenerate (an instant); see Self::instant.

Both endpoints share the same Timebase. To compare ranges across different timebases, rescale one of them first (e.g., by calling Timestamp::rescale_to on each endpoint).

Implementations§

Source§

impl TimeRange

Source

pub const fn new(start: i64, end: i64, timebase: Timebase) -> TimeRange

Creates a new TimeRange with the given start/end PTS and shared timebase.

§Panics
  • Panics if end < start (negative duration).
Source

pub const fn try_new( start: i64, end: i64, timebase: Timebase, ) -> Option<TimeRange>

Fallible variant of Self::new: returns None if end < start instead of panicking. Accepts start == end (degenerate instant range).

Source

pub const fn instant(ts: Timestamp) -> TimeRange

Creates a degenerate (instant) range where start == end == ts.pts().

Source

pub const fn start_pts(&self) -> i64

Returns the start PTS in the range’s timebase units.

Source

pub const fn end_pts(&self) -> i64

Returns the end PTS in the range’s timebase units.

Source

pub const fn timebase(&self) -> Timebase

Returns the shared timebase.

Source

pub const fn start(&self) -> Timestamp

Returns the start as a Timestamp.

Source

pub const fn end(&self) -> Timestamp

Returns the end as a Timestamp.

Source

pub const fn with_start(self, val: i64) -> TimeRange

Sets the start PTS.

Source

pub const fn set_start(&mut self, val: i64) -> &mut TimeRange

Sets the start PTS in place.

Source

pub const fn with_end(self, val: i64) -> TimeRange

Sets the end PTS.

Source

pub const fn set_end(&mut self, val: i64) -> &mut TimeRange

Sets the end PTS in place.

Source

pub const fn with_timebase(self, timebase: Timebase) -> TimeRange

Sets the shared timebase.

Source

pub const fn set_timebase(&mut self, timebase: Timebase) -> &mut TimeRange

Sets the shared timebase in place.

Source

pub const fn is_instant(&self) -> bool

Returns true if start == end (a degenerate instant range).

Source

pub const fn total_pts(&self) -> i64

Returns the span in PTS units (end - start) in this timebase.

Always non-negative given the start <= end constructor invariant. Saturates at i64::MAX in the pathological case where end - start would overflow i64 (e.g., start = i64::MIN, end = i64::MAX).

Source

pub const fn duration(&self) -> Duration

Returns the elapsed Duration from start to end, or None if end is before start.

Source

pub const fn rescale_to(self, target: Timebase) -> TimeRange

Returns a new TimeRange representing the same span in a different timebase.

Rescales both endpoints via Timebase::rescale_pts (rounds toward zero); round-tripping through a coarser timebase can lose precision. Because rescaling is monotonic, the start <= end invariant is preserved.

Source

pub const fn interpolate(&self, t: f64) -> Timestamp

Linearly interpolates between start and end: t = 0.0 returns start, t = 1.0 returns end, t = 0.5 the midpoint. t is clamped to [0.0, 1.0]. Rounds toward zero.

Use this to map an old-style bias value b ∈ [-1, 1] onto the range: range.interpolate((b + 1.0) * 0.5).

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for TimeRange

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<TimeRange, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Arbitrary for TimeRange

Source§

fn arbitrary(g: &mut Gen) -> TimeRange

Return an arbitrary value. Read more
Source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself. Read more
Source§

impl Clone for TimeRange

Source§

fn clone(&self) -> TimeRange

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TimeRange

Source§

fn default() -> TimeRange

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TimeRange

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<TimeRange, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for TimeRange

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TimeRange

Source§

fn eq(&self, other: &TimeRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TimeRange

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for TimeRange

Source§

impl Eq for TimeRange

Source§

impl StructuralPartialEq for TimeRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,