about summary refs log tree commit diff
path: root/src/libextra/dlist.rs
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-07-22 17:51:11 +0200
committerblake2-ppc <blake2-ppc>2013-07-22 17:51:11 +0200
commit52b4a2eb6f094db7eabcf605598b9266869fa9d6 (patch)
tree966fc89b57920c5f002c02f8d5b2d90c9057d4a3 /src/libextra/dlist.rs
parentcf437a273033a16c4084acc07b1341ee86bd5bbd (diff)
downloadrust-52b4a2eb6f094db7eabcf605598b9266869fa9d6.tar.gz
rust-52b4a2eb6f094db7eabcf605598b9266869fa9d6.zip
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.
Diffstat (limited to 'src/libextra/dlist.rs')
-rw-r--r--src/libextra/dlist.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs
index a715d4aeeae..276d8004314 100644
--- a/src/libextra/dlist.rs
+++ b/src/libextra/dlist.rs
@@ -477,7 +477,9 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, 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
@@ -515,6 +517,9 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, 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)
     }
 }