I don’t think this needs to be parameterized on
I at all. What would something like
slice::Iter even put there? The implementer already must be an
Iterator itself, so just return
struct Peekable, we still need the inherent (non-trait) method, otherwise you remove the ability to call
peek() without importing the new trait. But we can implement the trait method by calling the inherent method, or vice versa.
Later we can specialize
Peekable<I> where I: PeekableIterator such that it doesn’t need to use its own
peeked field at all, just forward to
I::peek(). I don’t think it’s possible to eliminate the field, but it can be ignored in this case.
We might also want a trait for
peek_back(), and then it’s possible to have something like:
impl<T> PeekableIterator for Rev<I>
where I: DoubleEndedPeekableIterator
But maybe I’m over-thinking it.