Struct pubgrub::range::Range

source ·
pub struct Range<V> { /* private fields */ }
Expand description

A Range represents multiple intervals of a continuous range of monotone increasing values.

Implementations§

source§

impl<V> Range<V>

source

pub fn empty() -> Self

Empty set of versions.

source

pub fn full() -> Self

Set of all possible versions

source

pub fn higher_than(v: impl Into<V>) -> Self

Set of all versions higher or equal to some version

source

pub fn strictly_higher_than(v: impl Into<V>) -> Self

Set of all versions higher to some version

source

pub fn strictly_lower_than(v: impl Into<V>) -> Self

Set of all versions lower to some version

source

pub fn lower_than(v: impl Into<V>) -> Self

Set of all versions lower or equal to some version

source

pub fn between(v1: impl Into<V>, v2: impl Into<V>) -> Self

Set of versions greater or equal to v1 but less than v2.

source

pub fn is_empty(&self) -> bool

Whether the set is empty, i.e. it has not ranges

source§

impl<V: Clone> Range<V>

source

pub fn singleton(v: impl Into<V>) -> Self

Set containing exactly one version

source

pub fn complement(&self) -> Self

Returns the complement of this Range.

source§

impl<V: Ord> Range<V>

source

pub fn as_singleton(&self) -> Option<&V>

If the range includes a single version, return it. Otherwise, returns None.

source

pub fn bounding_range(&self) -> Option<(Bound<&V>, Bound<&V>)>

Convert to something that can be used with BTreeMap::range. All versions contained in self, will be in the output, but there may be versions in the output that are not contained in self. Returns None if the range is empty.

source

pub fn contains(&self, version: &V) -> bool

Returns true if this Range contains the specified value.

source

pub fn contains_many<'s, I, BV>( &'s self, versions: I ) -> impl Iterator<Item = bool> + 's
where I: Iterator<Item = BV> + 's, BV: Borrow<V> + 's,

Returns true if this Range contains the specified values.

The versions iterator must be sorted. Functionally equivalent to versions.map(|v| self.contains(v)). Except it runs in O(size_of_range + len_of_versions) not O(size_of_range * len_of_versions)

source

pub fn from_range_bounds<R, IV>(bounds: R) -> Self
where R: RangeBounds<IV>, IV: Clone + Into<V>,

Construct a simple range from anything that impls RangeBounds like v1..v2.

source§

impl<V: Ord + Clone> Range<V>

source

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

Computes the union of this Range and another.

source

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

Computes the intersection of two sets of versions.

source

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

Return true if there can be no V so that V is contained in both self and other.

Note that we don’t know that set of all existing Vs here, so we only check if the segments are disjoint, not if no version is contained in both.

source

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

Return true if any V that is contained in self is also contained in other.

Note that we don’t know that set of all existing Vs here, so we only check if all segments self are contained in a segment of other.

source

pub fn simplify<'s, I, BV>(&self, versions: I) -> Self
where I: Iterator<Item = BV> + 's, BV: Borrow<V> + 's,

Returns a simpler Range that contains the same versions

For every one of the Versions provided in versions the existing range and the simplified range will agree on whether it is contained. The simplified version may include or exclude versions that are not in versions as the implementation wishes. For example:

  • If all the versions are contained in the original than the range will be simplified to full.
  • If none of the versions are contained in the original than the range will be simplified to empty.

If versions are not sorted the correctness of this function is not guaranteed.

source

pub fn iter(&self) -> impl Iterator<Item = (&Bound<V>, &Bound<V>)>

Iterate over the parts of the range.

Trait Implementations§

source§

impl<V: Clone> Clone for Range<V>

source§

fn clone(&self) -> Range<V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V: Debug> Debug for Range<V>

source§

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

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

impl<V: Display + Eq> Display for Range<V>

source§

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

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

impl<V: Hash> Hash for Range<V>

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<V: PartialEq> PartialEq for Range<V>

source§

fn eq(&self, other: &Range<V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Debug + Display + Clone + Eq + Ord> VersionSet for Range<T>

§

type V = T

Version type associated with the sets manipulated.
source§

fn empty() -> Self

Constructor for an empty set containing no version.
source§

fn singleton(v: Self::V) -> Self

Constructor for a set containing exactly one version.
source§

fn complement(&self) -> Self

Compute the complement of this set.
source§

fn intersection(&self, other: &Self) -> Self

Compute the intersection with another set.
source§

fn contains(&self, v: &Self::V) -> bool

Evaluate membership of a version in this set.
source§

fn full() -> Self

Constructor for the set containing all versions. Automatically implemented as Self::empty().complement().
source§

fn union(&self, other: &Self) -> Self

Compute the union with another set. Thanks to set properties, this is automatically implemented as: self.complement().intersection(&other.complement()).complement()
source§

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

Whether the range have no overlapping segmets
source§

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

Whether all range of self are contained in other
source§

impl<V: Eq> Eq for Range<V>

source§

impl<V> StructuralPartialEq for Range<V>

Auto Trait Implementations§

§

impl<V> Freeze for Range<V>
where V: Freeze,

§

impl<V> RefUnwindSafe for Range<V>
where V: RefUnwindSafe,

§

impl<V> Send for Range<V>
where V: Send,

§

impl<V> Sync for Range<V>
where V: Sync,

§

impl<V> Unpin for Range<V>
where V: Unpin,

§

impl<V> UnwindSafe for Range<V>
where V: 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<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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

§

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

source§

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

§

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

§

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.
source§

impl<T> Package for T
where T: Clone + Eq + Hash + Debug + Display,