diff --git a/src/range.rs b/src/range.rs index 5de98599..045c340a 100644 --- a/src/range.rs +++ b/src/range.rs @@ -462,8 +462,8 @@ impl Range { V: 'v, { // Do not simplify singletons - if self.is_singleton() { - return self.clone(); + if let Some(version) = self.as_singleton() { + return Self::singleton(version); } // Return the segment index in the range for each version in the range, None otherwise @@ -505,10 +505,18 @@ impl Range { Self { segments }.check_invariants() } - pub fn is_singleton(&self) -> bool { + /// If the range includes a single version, return it. + /// Otherwise, returns [None]. + pub fn as_singleton(&self) -> Option { match self.segments.as_slice() { - [(Included(v1), Included(v2))] => v1 == v2, - _ => false, + [(Included(v1), Included(v2))] => { + if v1 == v2 { + Some(v1.clone()) + } else { + None + } + } + _ => None, } } }