Next() for iterating for a non-Iterator

If next() is the most obvious name for what you're doing then I'd stick with it.

I personally find the "If it looks like Iterator::next() it should be Iterator::next()" argument pretty weak. There are no absolutes when it comes to how you write code and name things - it all depends on context. If your non-iterator iterator can't implement the Iterator trait because of technical reasons (e.g. Iterator doesn't work with lending iterators) that doesn't make it any less of an iterator.

If you wanted, you could even implement the lending_iterator::LendingIterator trait and have an inherent next() method which just delegates to <Self as lending_iterator::LendingIterator>::next() (so people don't need to import LendingIterator themselves). That'd stop all the naysayers because you are now implementing the right trait for the job while also giving people access to nice things like map(), rev(), and so on.

10 Likes