From 52b4a2eb6f094db7eabcf605598b9266869fa9d6 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Mon, 22 Jul 2013 17:51:11 +0200 Subject: [PATCH] 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. --- src/libextra/dlist.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 @@ fn next_back(&mut self) -> Option<&'self mut A> { /// Allow mutating the DList while iterating pub trait ListInsertion { - /// 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 @@ fn insert_next(&mut self, elt: 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) } } -- 2.44.0