Skip to content

Commit 52b4a2e

Browse files
author
blake2-ppc
committed
dlist: Fix .peek_next() w.r.t double ended iterators
.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.
1 parent cf437a2 commit 52b4a2e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libextra/dlist.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
477477

478478
/// Allow mutating the DList while iterating
479479
pub trait ListInsertion<A> {
480-
/// Insert `elt` just after to the most recently yielded element
480+
/// Insert `elt` just after to the element most recently returned by `.next()`
481+
///
482+
/// The inserted element does not appear in the iteration.
481483
fn insert_next(&mut self, elt: A);
482484

483485
/// Provide a reference to the next element, without changing the iterator
@@ -515,6 +517,9 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
515517

516518
#[inline]
517519
fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
520+
if self.nelem == 0 {
521+
return None
522+
}
518523
self.head.resolve().map_consume(|head| &mut head.value)
519524
}
520525
}

0 commit comments

Comments
 (0)