pub struct Range<T: PartialOrd> { /* private fields */ }Expand description
Inclusive [min, max] interval over a Rangeable type.
The constructor enforces min ≤ max, so a Range<T> value
in hand is a proof that the contained pair is well-ordered;
downstream consumers can read min /
max without re-checking. The invariant is
checked at runtime in debug builds via debug_assert!.
Construction sites in this crate (the Rangeable::range_across
reduction) walk the input iterator and produce a Range
directly; misuse — calling Range::new(b, a) with a < b —
is a programmer error and panics in debug, sneaks through in
release (the wrapped pair is then [max, min], so any caller
reading min gets the larger value). External
callers constructing a Range from external bounds should
pre-sort.
Range<T> deliberately omits Ord / PartialOrd /
Serialize / Deserialize:
- It is an in-memory aggregation result, not a wire-format
boundary; the
aggregate()dispatch destructuresRangeinto the existingcrate::ctprof_compare::Aggregated::OrdinalRangevariant (which carriesmin: i64, max: i64), so the typed invariant is enforced at the reduction boundary and the untyped tuple shape continues to cross every serialized boundary downstream. - Comparing two
Rangevalues to each other has no defined semantic — there is no obvious ordering on intervals — and addingderive(Ord)would bringstd::cmp::Ord::min/std::cmp::Ord::maxinto scope onRange<T>and shadow the inherent accessors at every call site.
Heads-up for future contributors: if Ord/PartialOrd
derives are ever added, expect breakage at every existing
.min() / .max() call site — those resolve to the
inherent methods today and will start resolving to the trait
methods (different signature, different return type) the
moment the derives are added.
Implementations§
Source§impl<T: PartialOrd> Range<T>
impl<T: PartialOrd> Range<T>
Sourcepub fn new(min: T, max: T) -> Self
pub fn new(min: T, max: T) -> Self
Construct a Range from a (min, max) pair.
debug_assert!s that min ≤ max — the Rangeable
reduction guarantees this by walking the input and
tracking min and max separately, so the assertion never
fires on internal call sites. External callers must
pre-sort.
Sourcepub fn into_tuple(self) -> (T, T)
pub fn into_tuple(self) -> (T, T)
Consume the range and return the (min, max) tuple.
Useful at boundaries where the caller has its own
pair-shaped representation (e.g. the
crate::ctprof_compare::Aggregated::OrdinalRange
variant).
Trait Implementations§
impl<T: Copy + PartialOrd> Copy for Range<T>
impl<T: Eq + PartialOrd> Eq for Range<T>
impl<T: PartialOrd> StructuralPartialEq for Range<T>
Auto Trait Implementations§
impl<T> Freeze for Range<T>where
T: Freeze,
impl<T> RefUnwindSafe for Range<T>where
T: RefUnwindSafe,
impl<T> Send for Range<T>where
T: Send,
impl<T> Sync for Range<T>where
T: Sync,
impl<T> Unpin for Range<T>where
T: Unpin,
impl<T> UnwindSafe for Range<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more