From d2727138277fe3845903839e8d0a95c046044d84 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 11 Mar 2024 22:07:33 +0100 Subject: [PATCH] feat: add a public `Range.iter()` method (#18) (#187) Co-authored-by: Zanie Blue 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 https://github.com/astral-sh/pubgrub/pull/18, but `impl Iterator, &Bound)>` instead of `impl Iterator, Bound)>` to avoid constraining it to a tuple. Co-authored-by: Zanie Blue --- src/range.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/range.rs b/src/range.rs index df39bea6..bbca4da2 100644 --- a/src/range.rs +++ b/src/range.rs @@ -508,6 +508,11 @@ impl Range { } Self { segments }.check_invariants() } + + /// Iterate over the parts of the range. + pub fn iter(&self) -> impl Iterator, &Bound)> { + self.segments.iter().map(|(start, end)| (start, end)) + } } impl VersionSet for Range {