diff --git a/src/range.rs b/src/range.rs index 7df77099..df39bea6 100644 --- a/src/range.rs +++ b/src/range.rs @@ -186,6 +186,21 @@ impl Range { } impl Range { + /// 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,