-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Implement intersection for two VersionReq #170
Comments
@Laegluin Did you ever end up looking at this? It would come in super handy for rust-lang/cargo#8890. |
Note that this could be a decent amount nicer with dtolnay/semver#170 This currently ends up in some kind of loop for cargo-like deps: yielding already-fetched rustversion yielding already-fetched futures yielding already-fetched thiserror yielding already-fetched anyhow yielding already-fetched rustversion yielding already-fetched futures yielding already-fetched thiserror Everything _up_ to that point terminates pretty quickly.
For what I needed I simply hacked it together by parsing the all requirements again: fn intersect(reqs: impl IntoIterator<Item = VersionReq>) -> VersionReq {
let reqs: Vec<_> = reqs
.into_iter()
.filter_map(|req| {
if req == VersionReq::any() {
None
} else {
Some(req.to_string())
}
})
.collect();
if reqs.is_empty() {
VersionReq::any()
} else {
reqs.join(", ").parse().unwrap()
}
} That's really ugly and probably not too fast but it works. Implementing this properly would probably just require merging the two vecs in the range: I'm not quite sure how the |
I feel like if we wanted "proper" support for this, we'd also look at the individual ranges and figure out where they overlap. That might produce significantly smaller requirements lists. Separately, I've also really wanted the ability to take the union of requirements. I think the process for that will also be very similar... |
Yeah, that would make a lot of sense, even though it's probably only worth it for the simple cases. In general all these types of features just come down to manipulating the list of ranges. I have to admit I am not particularly motivated to work on this at the moment, though. |
It would be useful to be able to merge to VersionReq into one that only matches Versions that both individual requirements match.
Something like this:
along with a version that takes an Iterator of VersionReq.
Considering that a VersionReq is only a Vec anyway, this should be fairly easy to implement. Unless somebody else wants it, I can do it.
The text was updated successfully, but these errors were encountered: