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

Support from creating Range from Bound #253

Closed
charliermarsh opened this issue Aug 29, 2024 · 7 comments
Closed

Support from creating Range from Bound #253

charliermarsh opened this issue Aug 29, 2024 · 7 comments

Comments

@charliermarsh
Copy link
Contributor

In uv, I have two Bound<Version> that I need to turn into a Range. I ended up doing this semi-manually here. It would be nice to have a public constructor, if appropriate.

@Eh2406
Copy link
Member

Eh2406 commented Aug 29, 2024

from_range_bounds?

@charliermarsh
Copy link
Contributor Author

Doesn't from_range_bounds require two Version? Like if v1 and v2 are Version, Range::from_range_bounds(v1..v2)?

@mpizenberg
Copy link
Member

It takes anything that implements RangeBounds. Here is the link to the docs: https://pubgrub-rs.github.io/pubgrub/pubgrub/range/struct.Range.html#method.from_range_bounds

And since it auto implemented for a pair of bounds I think you can direcly put a pair of bounds there: https://doc.rust-lang.org/nightly/core/ops/trait.RangeBounds.html#impl-RangeBounds%3CT%3E-for-(Bound%3CT%3E,+Bound%3CT%3E)

@konstin
Copy link
Member

konstin commented Aug 30, 2024

Thanks, I totally missed that!

In our use case, we pass in two RequiresPythonBound that impl Into<Bound<Version>>. The trick that i missed is that we need to eagerly convert into bounds, the Into<V> only applies to the version, not the type with the bound, and specify the target of the conversion:

Range::from_range_bounds::<(Bound<Version>, Bound<Version>), _>((
    value.0.into(),
    value.1.into(),
))

@charliermarsh
Copy link
Contributor Author

Got it, apologies. Skill issue!

@charliermarsh
Copy link
Contributor Author

Thanks for the clarification.

@Eh2406
Copy link
Member

Eh2406 commented Sep 1, 2024

@konstin, is there a better way for the generics on the fn? I'd be open to resuturing to make it EZer to use.

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

No branches or pull requests

4 participants