Skip to content

Commit 1f399d0

Browse files
committed
Rename UnindexedRangeLen::len to unindexed_len
This avoids potential ambiguity in case the standard library ever expands `ExactSizeIterator` to more ranges.
1 parent 5623fcf commit 1f399d0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/range.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ macro_rules! indexed_range_impl {
210210
}
211211

212212
trait UnindexedRangeLen<L> {
213-
fn len(&self) -> L;
213+
fn unindexed_len(&self) -> L;
214214
}
215215

216216
macro_rules! unindexed_range_impl {
217217
( $t:ty, $len_t:ty ) => {
218218
impl UnindexedRangeLen<$len_t> for Range<$t> {
219-
fn len(&self) -> $len_t {
219+
fn unindexed_len(&self) -> $len_t {
220220
let &Range { start, end } = self;
221221
if end > start {
222222
end.wrapping_sub(start) as $len_t
@@ -250,15 +250,15 @@ macro_rules! unindexed_range_impl {
250250
}
251251

252252
fn opt_len(iter: &Iter<$t>) -> Option<usize> {
253-
usize::try_from(iter.range.len()).ok()
253+
usize::try_from(iter.range.unindexed_len()).ok()
254254
}
255255
}
256256

257257
impl UnindexedProducer for IterProducer<$t> {
258258
type Item = $t;
259259

260260
fn split(mut self) -> (Self, Option<Self>) {
261-
let index = self.range.len() / 2;
261+
let index = self.range.unindexed_len() / 2;
262262
if index > 0 {
263263
let mid = self.range.start.wrapping_add(index as $t);
264264
let right = mid..self.range.end;
@@ -382,11 +382,14 @@ fn test_i128_len_doesnt_overflow() {
382382
range: 0..octillion,
383383
};
384384

385-
assert_eq!(octillion as u128, producer.range.len());
386-
assert_eq!(octillion as u128, (0..octillion).len());
387-
assert_eq!(2 * octillion as u128, (-octillion..octillion).len());
385+
assert_eq!(octillion as u128, producer.range.unindexed_len());
386+
assert_eq!(octillion as u128, (0..octillion).unindexed_len());
387+
assert_eq!(
388+
2 * octillion as u128,
389+
(-octillion..octillion).unindexed_len()
390+
);
388391

389-
assert_eq!(u128::MAX, (i128::MIN..i128::MAX).len());
392+
assert_eq!(u128::MAX, (i128::MIN..i128::MAX).unindexed_len());
390393
}
391394

392395
#[test]

0 commit comments

Comments
 (0)