Improve readability be replacing hard-to-read if-else branches with a match
@@ -372,7 +372,8 @@ impl HighlightedRangeStack {
} else {
let maybe_idx =
prev.iter().position(|parent| parent.range.contains(child.range.start()));
- if let (Some(_), Some(idx)) = (overwrite_parent, maybe_idx) {
+ match (overwrite_parent, maybe_idx) {
+ (Some(_), Some(idx)) => {
Self::intersect_partial(&mut prev[idx], &child);
let insert_idx = if prev[idx].range.is_empty() {
prev.remove(idx);
@@ -381,17 +382,20 @@ impl HighlightedRangeStack {
idx + 1
};
prev.insert(insert_idx, child);
- } else if let None = maybe_idx {
+ }
+ (_, None) => {
let idx = prev
.binary_search_by_key(&child.range.start(), |range| range.range.start())
.unwrap_or_else(|x| x);
prev.insert(idx, child);
- } else {
+ }
+ _ => {
unreachable!("child range should be completely contained in parent range");
}
}
}
}
+ }
fn add(&mut self, range: HighlightedRange) {
self.stack
