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).

§Equality and ordering

Equality is derived, and so structural: both counts are compared as written, and only the timebase is compared by value. [1500, 3250) @ 1/1000 therefore equals the same pair over 2/2000 but not [135_000, 292_500) over 1/90000, though they cover the same stretch of time. Hash agrees with that equality.

There is no Ord, the posture SignedDuration takes as well. Ranges have no single order to derive: by start, by end and by length are three different answers, and overlapping ranges are not ordered at all. Compare the part you mean — Self::start and Self::end hand back Timestamps, which are ordered, and by the instant rather than by the count.

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.

§Panics

Panics if end precedes start, which every constructor refuses and Self::rescale_to preserves — so this is unreachable for a range built through the public API. It is reachable through the buffa decoder, which admits an inverted range from the wire.

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::saturating_rescale, to the nearest tick of target; round-tripping through a coarser timebase can lose precision. Because rescaling is monotonic, the start <= end invariant is preserved.

§Panics

Panics if target.num() == 0, as Timebase::saturating_rescale does.

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 Arbitrary for TimeRange

Source§

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

Return an arbitrary value. Read more
Source§

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

Return an iterator of values that are smaller than itself. Read more
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 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 Copy for TimeRange

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 Display for TimeRange

Writes both endpoints as clocks inside interval notation: [0:00:01.500, 0:00:03.250).

The mismatched brackets are the point rather than decoration. This type is half-open — closed at start, open at end — and […) is the notation that says so, where a dash or an ellipsis would leave a reader to guess whether end is inside. The rendering therefore teaches the semantics the type documents.

{:#} prints the raw endpoints and names the shared timebase once, after both — [1500, 3250) @ 1/1000 — because both endpoints are in one timebase by construction and repeating it would suggest they need not be. The derived Debug is exact as well, and {:#} is the form FromStr reads back.

Each endpoint is rendered by Timestamp’s Display, and inherits its truncation, its lossiness, and its indifference to width and alignment flags.

Source§

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

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

impl Eq for TimeRange

Source§

impl FromStr for TimeRange

Parses [start, end) @ num/den — the form TimeRange’s Display writes under {:#}.

The half-open brackets are required, in that asymmetry, because they are what the rendering means. Whitespace around each part is trimmed. The default {} form, a pair of clocks, is not accepted, for the reason Timestamp’s is not.

§Errors

Returns ParseTimeRangeError if the bracket, comma, or @ is missing, if an endpoint is not an i64, if the timebase half is not one Timebase accepts, or if the endpoints run backwards.

Source§

type Err = ParseTimeRangeError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<TimeRange, <TimeRange as FromStr>::Err>

Parses a string s to return a value of this type. 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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 StructuralPartialEq for TimeRange

Source§

impl TryFrom<TimeRangeRepr> for TimeRange

Source§

type Error = InvertedRange

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

fn try_from( repr: TimeRangeRepr, ) -> Result<TimeRange, <TimeRange as TryFrom<TimeRangeRepr>>::Error>

Performs the conversion.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.