Skip to content

Commit

Permalink
feat: add Range::as_singleton (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin authored Mar 11, 2024
1 parent fdd9cc9 commit a20c414
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ impl<V: Clone> Range<V> {
}

impl<V: Ord> Range<V> {
/// If the range includes a single version, return it.
/// Otherwise, returns [None].
pub fn as_singleton(&self) -> Option<&V> {
match self.segments.as_slice() {
[(Included(v1), Included(v2))] => {
if v1 == v2 {
Some(v1)
} else {
None
}
}
_ => None,
}
}

/// Convert to something that can be used with
/// [BTreeMap::range](std::collections::BTreeMap::range).
/// All versions contained in self, will be in the output,
Expand Down

0 comments on commit a20c414

Please sign in to comment.