i is usize; I tried enumerate::<u64>(), but it is not so simple. I did some research, found only some ad hoc solutions, none of them relevant to the enumerate() case. Is it really so difficult?
Sure. But I have in mind the case of a 32-bit architecture. Suppose my (lazy) iterator has a real chance to break 65535 limit? If this happens, type cast is worse than useless.
If you have a 32-bit architecture, then usize is 32 bits (except for weird archs), and so casting usize to u64 should never impose any loss of information.
If the number of elements in your iterator exceeds the addressable memoryusize::MAX, then enumerate() will misbehave (wrap around or panic, I don't remember) anyway, and so you've got a much worse problem to deal with than a useless cast.
It's not about space. An iterator that produces so
many elements that it overflows usize is problematic whether or not it tries to allocate 4 billion elements.
I think that iterators potentially longer than 32-bit usize are quite practical. It only takes a few seconds to count that many things if you can process them quickly.
People above seem to have missed the solution that @Cyborus04 and @scottmcm posted, so here it is more explicitly: