.peek_next() needs to check the element counter just like the .next()
and .next_back() iterators do.
Also clarify .insert_next() doc w.r.t double ended iteration.
/// Allow mutating the DList while iterating
pub trait ListInsertion<A> {
/// Allow mutating the DList while iterating
pub trait ListInsertion<A> {
- /// Insert `elt` just after to the most recently yielded element
+ /// Insert `elt` just after to the element most recently returned by `.next()`
+ ///
+ /// The inserted element does not appear in the iteration.
fn insert_next(&mut self, elt: A);
/// Provide a reference to the next element, without changing the iterator
fn insert_next(&mut self, elt: A);
/// Provide a reference to the next element, without changing the iterator
#[inline]
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
#[inline]
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
+ if self.nelem == 0 {
+ return None
+ }
self.head.resolve().map_consume(|head| &mut head.value)
}
}
self.head.resolve().map_consume(|head| &mut head.value)
}
}