Trait VersionSet

Source
pub trait VersionSet:
    Debug
    + Display
    + Clone
    + Eq {
    type V: Debug + Display + Clone + Ord;

    // Required methods
    fn empty() -> Self;
    fn singleton(v: Self::V) -> Self;
    fn complement(&self) -> Self;
    fn intersection(&self, other: &Self) -> Self;
    fn contains(&self, v: &Self::V) -> bool;

    // Provided methods
    fn full() -> Self { ... }
    fn union(&self, other: &Self) -> Self { ... }
    fn is_disjoint(&self, other: &Self) -> bool { ... }
    fn subset_of(&self, other: &Self) -> bool { ... }
}
Expand description

A set of versions.

See Ranges for an implementation.

The methods with default implementations can be overwritten for better performance, but their output must be equal to the default implementation.

§Equality

It is important that the Eq trait is implemented so that if two sets contain the same versions, they are equal under Eq. In particular, you can only use #[derive(Eq, PartialEq)] if Eq is strictly equivalent to the structural equality, i.e. if version sets are always stored in a canonical representations. Such problems may arise if your implementations of complement() and intersection() do not return canonical representations.

For example, >=1,<4 || >=2,<5 and >=1,<4 || >=3,<5 are equal, because they can both be normalized to >=1,<5.

Note that pubgrub does not know which versions actually exist for a package, the contract is about upholding the mathematical properties of set operations, assuming all versions are possible. This is required for the solver to determine the relationship of version sets to each other.

Required Associated Types§

Source

type V: Debug + Display + Clone + Ord

Version type associated with the sets manipulated.

Required Methods§

Source

fn empty() -> Self

An empty set containing no version.

Source

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

A set containing only the given version.

Source

fn complement(&self) -> Self

The set of all version that are not in this set.

Source

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

The set of all versions that are in both sets.

Source

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

Whether the version is part of this set.

Provided Methods§

Source

fn full() -> Self

The set containing all versions.

The default implementation is the complement of the empty set.

Source

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

The set of all versions that are either (or both) of the sets.

The default implementation is complement of the intersection of the complements of both sets (De Morgan’s law).

Source

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

Whether the ranges have no overlapping segments.

Source

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

Whether all ranges of self are contained in other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Ranges contains optimized implementations of all operations.

Source§

type V = T