diff --git a/src/range.rs b/src/range.rs index c4ea21dd..a9cfc886 100644 --- a/src/range.rs +++ b/src/range.rs @@ -124,6 +124,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 {