Skip to main content

RangePosition

Struct RangePosition 

Source
pub struct RangePosition {
    pub lower: BoundOrdering,
    pub upper: BoundOrdering,
}
Expand description

Full position of a value relative to a range, expressed as the pair of its relationships to the lower and the upper bound.

Keeping both relationships separate is what allows PartialRangeOrd to stay honest over partial orders: a value can be, say, comparable with the lower bound and incomparable with the upper one, and the information is preserved instead of being flattened into a single ambiguous verdict.

Fields§

§lower: BoundOrdering

Relationship of the value to the lower bound. Within means the value satisfies the lower bound, Outside means it is below it.

§upper: BoundOrdering

Relationship of the value to the upper bound. Within means the value satisfies the upper bound, Outside means it is above it.

Implementations§

Source§

impl RangePosition

Source

pub fn is_inside(&self) -> bool

Returns whether the value lies inside the range, i.e. it satisfies both bounds.

use range_cmp::PartialRangeOrd;
assert!(2.5_f64.partial_rcmp(2.0..3.0).is_inside());
assert!(!3.5_f64.partial_rcmp(2.0..3.0).is_inside());
Source

pub fn ordering(&self) -> Option<RangeOrdering>

Collapses the pair into a simple RangeOrdering when possible.

Returns None when the value is incomparable with at least one bound, in which case no single Below/Inside/Above/Empty verdict captures the position; inspect the lower and upper fields directly in that case.

The (Outside, Outside) case — being simultaneously below the lower bound and above the upper bound — can only occur for an empty (inverted) range, and is reported as RangeOrdering::Empty.

Trait Implementations§

Source§

impl Clone for RangePosition

Source§

fn clone(&self) -> RangePosition

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 RangePosition

Source§

impl Debug for RangePosition

Source§

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

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

impl Eq for RangePosition

Source§

impl Hash for RangePosition

Source§

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

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 RangePosition

Source§

fn eq(&self, other: &RangePosition) -> 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 StructuralPartialEq for RangePosition

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