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 Range::iter() method #187

Merged
merged 1 commit into from
Mar 11, 2024
Merged

Conversation

@konstin konstin changed the title Add a public Range.iter() method (#18) Add a public Range.iter() method Mar 11, 2024
@konstin konstin force-pushed the konsti/add-range-iter branch from 3a86fd0 to cbe0f18 Compare March 11, 2024 20:35
@konstin konstin changed the title Add a public Range.iter() method Add a Range::iter() method Mar 11, 2024
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>)> {
Copy link
Member

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?

Copy link
Member Author

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 👍

Copy link
Member

@Eh2406 Eh2406 left a 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.
@konstin konstin force-pushed the konsti/add-range-iter branch from cbe0f18 to 58766a9 Compare March 11, 2024 20:46
@Eh2406 Eh2406 added this pull request to the merge queue Mar 11, 2024
Merged via the queue into pubgrub-rs:dev with commit d272713 Mar 11, 2024
5 checks passed
@konstin konstin deleted the konsti/add-range-iter branch March 11, 2024 21:21
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 this pull request may close these issues.

3 participants