Skip to main content

AnyRange

Struct AnyRange 

Source
pub struct AnyRange<T>(/* private fields */)
where
    T: NumericInteger;
Expand description

The set type this crate operates on, and the range type its constructors take, are irange’s. They are re-exported here so that a dependent needs neither its own dependency on irange nor a version kept in step with this crate’s. A range of integers, held as an inclusive (min, max) pair.

A range where min > max is empty and is ignored by RangeSet::new_from_ranges.

Implementations§

Source§

impl<T> AnyRange<T>
where T: NumericInteger,

Source

pub fn new(min: T, max: T) -> AnyRange<T>

Create a range from the given inclusive bounds.

The range is empty if min > max.

Source

pub fn from<R>(range: R) -> AnyRange<T>
where R: RangeBounds<T>,

Create a range from any Rust range, inclusive or not, bounded or not.

The range is empty if it holds no value, e.g. 2..2 or ..T::MIN.

§Example:
use irange::range::AnyRange;

// Holds 3, 4
assert_eq!(&(3, 4), AnyRange::from(3..5).get_bounds());

// Holds 0, 1, 2
assert_eq!(&(0, 2), AnyRange::<u8>::from(..=2).get_bounds());

assert!(AnyRange::from(2..2).is_empty());
Source

pub fn get_bounds(&self) -> &(T, T)

Return the inclusive (min, max) bounds of the range.

min is greater than max when the range is empty.

Source

pub fn is_empty(&self) -> bool

Return true if the range holds no value, i.e. if min > max.

§Example:
use irange::range::AnyRange;

assert!(AnyRange::new(4, 3).is_empty());
assert!(!AnyRange::new(3, 4).is_empty());

Trait Implementations§

Source§

impl<T> Clone for AnyRange<T>
where T: Clone + NumericInteger,

Source§

fn clone(&self) -> AnyRange<T>

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<T> Copy for AnyRange<T>
where T: Copy + NumericInteger,

Source§

impl<T> Debug for AnyRange<T>
where T: Debug + NumericInteger,

Source§

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

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

impl<T> Eq for AnyRange<T>
where T: Eq + NumericInteger,

Source§

impl<T> FromIterator<AnyRange<T>> for RangeSet<T>
where T: NumericInteger,

Source§

fn from_iter<I>(iter: I) -> RangeSet<T>
where I: IntoIterator<Item = AnyRange<T>>,

Collect the given ranges into a single set, like RangeSet::new_from_ranges.

§Example:
use irange::range::AnyRange;
use irange::RangeSet;

let range: RangeSet<i64> = [3..=4, 7..=8].into_iter().map(AnyRange::from).collect();
assert_eq!("[ 3..=4 7..=8 ]", range.to_string());
Source§

impl<T> Hash for AnyRange<T>
where T: Hash + NumericInteger,

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<T> Ord for AnyRange<T>
where T: Ord + NumericInteger,

Source§

fn cmp(&self, other: &AnyRange<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T> PartialEq for AnyRange<T>

Source§

fn eq(&self, other: &AnyRange<T>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<T> PartialOrd for AnyRange<T>

Source§

fn partial_cmp(&self, other: &AnyRange<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> StructuralPartialEq for AnyRange<T>

Auto Trait Implementations§

§

impl<T> Freeze for AnyRange<T>
where (T, T): Freeze,

§

impl<T> RefUnwindSafe for AnyRange<T>

§

impl<T> Send for AnyRange<T>
where (T, T): Send,

§

impl<T> Sync for AnyRange<T>
where (T, T): Sync,

§

impl<T> Unpin for AnyRange<T>
where (T, T): Unpin,

§

impl<T> UnsafeUnpin for AnyRange<T>

§

impl<T> UnwindSafe for AnyRange<T>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.