Skip to content

Feature Request: Compatibility with PubGrub::VersionSet #346

@parthkalgaonkar

Description

@parthkalgaonkar

pubgrub-rs provides implementation for dependency tree resolution. I'm trying to integrate semver with pubgrub in my project.

I want to implement the pubgrub::VersionSet trait for semver::VersionReq.

Initially I thought of creating a wrapper type and implementing the trait for that, but it needs the following methods:

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

  // Constructors

  /// An empty set containing no version.
  fn empty() -> Self; // Easy enough to handle in the wrapper

  /// A set containing only the given version.
  fn singleton(v: Self::V) -> Self;  // trivial using the Op::Exact comparator

  // Operations

  /// The set of all version that are not in this set.
  fn complement(&self) -> Self;  // <-------------------- This is difficult

  /// The set of all versions that are in both sets.
  fn intersection(&self, other: &Self) -> Self; // Essentially concatenation of the two Vec<Comparator>s

  /// Whether the version is part of this set.
  fn contains(&self, v: &Self::V) -> bool; // Trivial using VersionReq::matches
}

All of the pubgrub::VersionSet trait members are easy enough to implement apart from the complement.

One approach I thought of was to take the individual Comparators and negate them as required. but I'd have to implement my own version of semver::eval::matches_comparator since that function is private to the semver crate.

Do you think there is value in having this functionality as part of semver. Otherwise, would you be open to making the eval::matches_comparator function public so I can reuse that functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions