Skip to content

Commit d272713

Browse files
konstinzanieb
andauthored
feat: add a public Range.iter() method (#18) (pubgrub-rs#187)
Co-authored-by: Zanie Blue <contact@zanie.dev> 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 <contact@zanie.dev>
1 parent a20c414 commit d272713

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/range.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ impl<V: Ord + Clone> Range<V> {
508508
}
509509
Self { segments }.check_invariants()
510510
}
511+
512+
/// Iterate over the parts of the range.
513+
pub fn iter(&self) -> impl Iterator<Item = (&Bound<V>, &Bound<V>)> {
514+
self.segments.iter().map(|(start, end)| (start, end))
515+
}
511516
}
512517

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

0 commit comments

Comments
 (0)