Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to check if all Predicates in some VersionReq contains some Op #191

Closed
hbina opened this issue Oct 1, 2019 · 1 comment
Closed

Comments

@hbina
Copy link

hbina commented Oct 1, 2019

Hello,

I am trying to resolve this issue here : rust-lang/cargo#5340
But to do that --- without resorting to copying the behavior of VersionReq --- I would need an API that can easily let me check if all of my Predicates in some VersionReq matches some Op.

I would like something like this to be possible,

(semver::VersionReq).contains_op(semver::Op).

I believe this will require couple of changes:

  1. Op is now a public enum
  2. Add a new method contains_op that takes an Op and returns a bool as described above.

Thank you!

@hbina hbina changed the title E Add a method to check if all Predicates in some VersionReq contains some Op Oct 1, 2019
@dtolnay
Copy link
Owner

dtolnay commented May 25, 2021

As of 1.0.0, this logic is now possible to implement downstream, and doesn't need to be built into this crate.

use semver::{Op, VersionReq};

fn contains_op(req: &VersionReq, op: Op) -> bool {
    req.comparators.iter().all(|cmp| cmp.op == op)
}

@dtolnay dtolnay closed this as completed May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants