Add slice::check_range
by dylni · Pull Request #75207 · rust-lang/rust (original) (raw)
There are 3 more ad-hoc implementations:
match (range.start_bound(), range.end_bound()) { (Excluded(s), Excluded(e)) if s == e => { panic!("range start and end are equal and excluded in BTreeMap") } (Included(s) | Excluded(s), Included(e) Excluded(e)) if s > e => { panic!("range start is greater than range end in BTreeMap") } _ => {} };
The bounds aren't integers, and they're not used for a slice.
let start = match start { Bound::Included(lo) => lo, Bound::Excluded(lo) => lo + 1, Bound::Unbounded => 0, };
| let end = match end { |
| Bound::Included(hi) => hi + 1, |
| Bound::Excluded(hi) => hi, |
| Bound::Unbounded => length, |
| }; |
I don't think this method is allowed to panic, but it also doesn't use a slice.
let start = match range.start_bound() { Bound::Included(ref k) => match self.lookup_index_for(k) { Ok(index) | Err(index) => index, }, Bound::Excluded(ref k) => match self.lookup_index_for(k) { Ok(index) => index + 1, Err(index) => index, }, Bound::Unbounded => 0, };
| let end = match range.end_bound() { |
| Bound::Included(ref k) => match self.lookup_index_for(k) { |
| Ok(index) => index + 1, |
| Err(index) => index, |
| }, |
| Bound::Excluded(ref k) => match self.lookup_index_for(k) { |
| Ok(index) | Err(index) => index, |
| }, |
| Bound::Unbounded => self.data.len(), |
| }; |
I don't see any way check_range
could be defined that would help here.