-
Notifications
You must be signed in to change notification settings - Fork 38
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 Range::iter()
method
#187
Conversation
Range.iter()
method (#18)Range.iter()
method
3a86fd0
to
cbe0f18
Compare
src/range.rs
Outdated
@@ -493,6 +493,11 @@ impl<V: Ord + Clone> Range<V> { | |||
} | |||
Self { segments }.check_invariants() | |||
} | |||
|
|||
/// Iterate over the parts of the range. | |||
pub fn iter(&self) -> impl Iterator<Item = &(Bound<V>, Bound<V>)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be Item = (&Bound<V>, &Bound<V>)
, so that our API does not require us to store this in a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked with uv, we can 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit otherwise I agree that this looks useful. It a little bit locks us into this representation, but the Range Trait can always add another implementation if we find a better one.
Co-authored-by: Zanie Blue <[email protected]> Otherwise, it's not possible to implement custom formatting of `Range` types. This seems generally useful to expose. Example usages: https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L97-L112 https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L549-L560 https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L568-L605 Upstream port of #18, but `impl Iterator<Item = (&Bound<V>, &Bound<V>)>` instead of `impl Iterator<Item = &(Bound<V>, Bound<V>)>` to avoid constraining it to a tuple.
cbe0f18
to
58766a9
Compare
Otherwise, it's not possible to implement custom formatting of
Range
types. This seems generally useful to expose.Example usages:
https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L97-L112
https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L549-L560
https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L568-L605
Upstream port of astral-sh#18