Skip to main content

Window

Struct Window 

Source
pub struct Window<P: Profile> { /* private fields */ }
Expand description

A closed interval in absolute time, lo <= hi.

Rule U: window arithmetic is interval arithmetic with outward rounding. Windows are never silently collapsed — Window::midpoint must be called explicitly and takes a Rounding.

Implementations§

Source§

impl<P: Profile> Window<P>

Source

pub fn new(lo: Instant<P>, hi: Instant<P>) -> Result<Self>

Construct from bounds, rejecting inversion with UCAL-E0022.

Source

pub fn exact(at: Instant<P>) -> Self

The degenerate window at a single tick.

Source

pub fn lo(&self) -> &Instant<P>

Lower bound.

Source

pub fn hi(&self) -> &Instant<P>

Upper bound.

Source

pub fn width(&self) -> Delta

Width in ticks. A degenerate window has width zero, not one: it spans one tick, and the width is the difference between its bounds.

Source

pub fn is_exact(&self) -> bool

Whether the window spans exactly one tick.

Source

pub fn contains(&self, t: &Instant<P>) -> bool

Whether an instant lies within the closed interval.

Source

pub fn overlaps(&self, other: &Self) -> bool

Whether two windows overlap.

Source

pub fn compare(&self, other: &Self) -> IntervalOrdering

Interval-aware comparison, which may be indeterminate (Rule T).

Source

pub fn try_compare(&self, other: &Self) -> Result<Ordering>

Interval-aware comparison as a Result, so that indeterminacy surfaces as UCAL-E0023 at call sites that require a total order.

Source

pub fn checked_add(&self, d: &Delta) -> Result<Self>

Shift the whole window by a magnitude. Outward rounding is trivial here because a translation preserves width exactly (Rule U).

Source

pub fn checked_sub(&self, d: &Delta) -> Result<Self>

Shift the window back by a magnitude.

Source

pub fn widen(&self, d: &Delta) -> Result<(Self, bool)>

Widen outward by a magnitude on both sides. The lower bound saturates at the datum rather than failing, because a window clipped by Rule Z is still a sound enclosure; the clipping is reported by the returned flag.

Source

pub fn checked_add_span(&self, s: &Span) -> Result<Self>

Shift by an uncertain magnitude: lo with lo, hi with hi (Rule U).

The result is at least as wide as either input, which is the point — an uncertain instant displaced by an uncertain duration cannot be known better than either. This is the operation Rule J.2 needs when an anchor window is carried forward into a derived field.

Source

pub fn checked_sub_span(&self, s: &Span) -> Result<Self>

Shift back by an uncertain magnitude: [lo - s.hi, hi - s.lo], outward.

Strict at the datum — UCAL-E0020 rather than a clamp — because a window that has been silently clipped is no longer the interval the caller asked for. Use Window::widen where clipping is acceptable and reported.

Source

pub fn since_window(&self, earlier: &Self) -> Result<(Span, bool)>

Elapsed time from an earlier window to this one, as an uncertain magnitude.

[max(0, self.lo - earlier.hi), self.hi - earlier.lo]. The lower bound clamps at zero because overlapping windows genuinely admit zero elapsed time; the flag reports whether that happened. UCAL-E0020 when this window lies wholly before earlier, which is Rule Z applied to intervals.

Source

pub fn hull(&self, other: &Self) -> Self

The union enclosure of two windows — the smallest window containing both.

Source

pub fn intersect(&self, other: &Self) -> Option<Self>

The intersection, or None if the windows are disjoint.

Source

pub fn midpoint(&self, mode: Rounding) -> Result<Instant<P>>

Collapse to a single instant under an explicit rounding mode.

Rule U forbids collapsing a window silently, so this is deliberately a named call that cannot be reached by coercion.

Trait Implementations§

Source§

impl<P: Profile> Clone for Window<P>

Source§

fn clone(&self) -> Self

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<P: Profile> Copy for Window<P>

Available on crate feature u512 only.
Source§

impl<P: Profile> Debug for Window<P>

Source§

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

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

impl<P: Profile> Eq for Window<P>

Source§

impl<P: Profile> PartialEq for Window<P>

Source§

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

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<P> Freeze for Window<P>

§

impl<P> RefUnwindSafe for Window<P>
where P: RefUnwindSafe,

§

impl<P> Send for Window<P>
where P: Send,

§

impl<P> Sync for Window<P>
where P: Sync,

§

impl<P> Unpin for Window<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Window<P>

§

impl<P> UnwindSafe for Window<P>
where P: UnwindSafe,

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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.