Skip to content

Commit

Permalink
feat: add Range::is_empty() and Range::bounds()
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored and konstin committed Mar 11, 2024
1 parent a23e746 commit be6883f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ impl<V> Range<V> {
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<Item = &V> {
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<V: Clone> Range<V> {
Expand Down

0 comments on commit be6883f

Please sign in to comment.