From 3549dc50cb8cb03e1e6d0d8e0bbd9ad502d80d07 Mon Sep 17 00:00:00 2001 From: konsti Date: Tue, 12 Mar 2024 14:48:43 +0100 Subject: [PATCH] feat: add `Range::is_empty()` (#189) We use `Range::is_empty()` for special casing the empty version range in error messages. This mirrors std, which has `is_empty` methods on all of its collections: https://doc.rust-lang.org/nightly/std/?search=is_empty Example usages: https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L553 https://github.com/astral-sh/uv/blob/8d721830db8ad75b8b7ef38edc0e346696c52e3d/crates/uv-resolver/src/pubgrub/report.rs#L565 --- src/range.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/range.rs b/src/range.rs index bbca4da2..a7eb0e82 100644 --- a/src/range.rs +++ b/src/range.rs @@ -119,6 +119,11 @@ impl Range { segments: SmallVec::one((Included(v1.into()), Excluded(v2.into()))), } } + + /// Whether the set is empty, i.e. it has not ranges + pub fn is_empty(&self) -> bool { + self.segments.is_empty() + } } impl Range {