From cbe0f18ee78ae9ed2daac65c5d110a885e982583 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 9 Jan 2024 20:05:58 -0600 Subject: [PATCH] feat: add a public `Range.iter()` method (#18) 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 --- src/range.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/range.rs b/src/range.rs index 7df77099..900fbe5d 100644 --- a/src/range.rs +++ b/src/range.rs @@ -493,6 +493,11 @@ impl Range { } Self { segments }.check_invariants() } + + /// Iterate over the parts of the range. + pub fn iter(&self) -> impl Iterator, Bound)> { + self.segments.iter() + } } impl VersionSet for Range {