From 654e9930e7e2bbcc7729cbcca08e4aef6fe6d079 Mon Sep 17 00:00:00 2001 From: Yosh Date: Tue, 22 Nov 2022 16:33:29 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Consoli --- src/utils/indexer.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/indexer.rs b/src/utils/indexer.rs index afcbadd..9da6227 100644 --- a/src/utils/indexer.rs +++ b/src/utils/indexer.rs @@ -17,11 +17,10 @@ impl Indexer { pub(crate) fn iter(&mut self) -> IndexIter { // Increment the starting point for next time. let offset = self.offset; - self.offset = self.offset.wrapping_rem(self.max); + self.offset = (self.offset + 1).wrapping_rem(self.max); IndexIter { iter: (0..self.max), - max: self.max, offset, } } @@ -30,7 +29,6 @@ impl Indexer { pub(crate) struct IndexIter { iter: ops::Range, offset: usize, - max: usize, } impl Iterator for IndexIter { @@ -39,6 +37,6 @@ impl Iterator for IndexIter { fn next(&mut self) -> Option { self.iter .next() - .map(|pos| (pos + self.offset).wrapping_rem(self.max)) + .map(|pos| (pos + self.offset).wrapping_rem(self.iter.end)) } }