Add Range[Inclusive]::is_empty
During the RFC, it was discussed that figuring out whether a range is empty was subtle, and thus there should be a clear and obvious way to do it. It can't just be ExactSizeIterator::is_empty (also unstable) because not all ranges are ExactSize -- not even Range<i32> or RangeInclusive<usize>.
This commit is contained in:
parent
afa8acce25
commit
4f8049a2b0
5 changed files with 62 additions and 5 deletions
|
@ -1427,9 +1427,9 @@ fn test_range_inclusive_nth() {
|
|||
assert_eq!(r, 13..=20);
|
||||
assert_eq!(r.nth(2), Some(15));
|
||||
assert_eq!(r, 16..=20);
|
||||
assert_eq!(r.is_empty(), false);
|
||||
assert_eq!(ExactSizeIterator::is_empty(&r), false);
|
||||
assert_eq!(r.nth(10), None);
|
||||
assert_eq!(r.is_empty(), true);
|
||||
assert_eq!(ExactSizeIterator::is_empty(&r), true);
|
||||
assert_eq!(r, 1..=0); // We may not want to document/promise this detail
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue