We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Range::as_singleton
1 parent fdd9cc9 commit a20c414Copy full SHA for a20c414
src/range.rs
@@ -186,6 +186,21 @@ impl<V: Clone> Range<V> {
186
}
187
188
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
+
204
/// Convert to something that can be used with
205
/// [BTreeMap::range](std::collections::BTreeMap::range).
206
/// All versions contained in self, will be in the output,
0 commit comments