Skip to content

Commit 78b8add

Browse files
charliermarshkonstin
authored andcommitted
Add Range::bounds (#16)
1 parent 0d63cc6 commit 78b8add

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/range.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ impl<V> Range<V> {
122122
pub fn is_empty(&self) -> bool {
123123
self.segments.is_empty()
124124
}
125+
126+
/// Return all boundary versions of this range.
127+
pub fn bounds(&self) -> impl Iterator<Item = &V> {
128+
self.segments.iter().flat_map(|segment| {
129+
let (v1, v2) = segment;
130+
let v1 = match v1 {
131+
Included(v) => Some(v),
132+
Excluded(v) => Some(v),
133+
Unbounded => None,
134+
};
135+
let v2 = match v2 {
136+
Included(v) => Some(v),
137+
Excluded(v) => Some(v),
138+
Unbounded => None,
139+
};
140+
v1.into_iter().chain(v2)
141+
})
142+
}
125143
}
126144

127145
impl<V: Clone> Range<V> {

0 commit comments

Comments
 (0)