Skip to content

Commit a20c414

Browse files
authored
1 parent fdd9cc9 commit a20c414

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/range.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ impl<V: Clone> Range<V> {
186186
}
187187

188188
impl<V: Ord> Range<V> {
189+
/// If the range includes a single version, return it.
190+
/// Otherwise, returns [None].
191+
pub fn as_singleton(&self) -> Option<&V> {
192+
match self.segments.as_slice() {
193+
[(Included(v1), Included(v2))] => {
194+
if v1 == v2 {
195+
Some(v1)
196+
} else {
197+
None
198+
}
199+
}
200+
_ => None,
201+
}
202+
}
203+
189204
/// Convert to something that can be used with
190205
/// [BTreeMap::range](std::collections::BTreeMap::range).
191206
/// All versions contained in self, will be in the output,

0 commit comments

Comments
 (0)