Skip to content

Commit

Permalink
feat: add a public Range.iter() method (#18) (pubgrub-rs#187)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Zanie Blue <[email protected]>
  • Loading branch information
konstin and zanieb authored Mar 11, 2024
1 parent a20c414 commit d272713
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,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>)> {
self.segments.iter().map(|(start, end)| (start, end))
}
}

impl<T: Debug + Display + Clone + Eq + Ord> VersionSet for Range<T> {
Expand Down

0 comments on commit d272713

Please sign in to comment.