diff --git a/src/range.rs b/src/range.rs index 7df77099..0e7335bc 100644 --- a/src/range.rs +++ b/src/range.rs @@ -119,6 +119,29 @@ 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() + } + + /// 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 {