From 3b013da32e9e663754e3a9860825c185223a77b0 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 28 Dec 2023 13:49:48 -0400 Subject: [PATCH] Add Range::bounds (#16) --- src/range.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/range.rs b/src/range.rs index fc04e8b0..bf689c6d 100644 --- a/src/range.rs +++ b/src/range.rs @@ -122,6 +122,24 @@ impl Range { pub fn is_empty(&self) -> bool { self.segments.is_empty() } + + /// Return all boundary versions of this range. + pub fn bounds(&self) -> impl Iterator { + self.segments.iter().flat_map(|segment| { + let (v1, v2) = segment; + let v1 = match v1 { + Included(v) => Some(v), + Excluded(v) => Some(v), + Unbounded => None, + }; + let v2 = match v2 { + Included(v) => Some(v), + Excluded(v) => Some(v), + Unbounded => None, + }; + v1.into_iter().chain(v2) + }) + } } impl Range {