@@ -653,6 +653,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> {
653653impl < ' a , A > ExactSizeIterator < & ' a mut A > for IterMut < ' a , A > { }
654654
655655/// Allows mutating a `DList` while iterating.
656+ #[ deprecated = "Trait is deprecated, use inherent methods on the iterator instead" ]
656657pub trait ListInsertion < A > {
657658 /// Inserts `elt` just after to the element most recently returned by
658659 /// `.next()`
@@ -687,14 +688,50 @@ impl<'a, A> IterMut<'a, A> {
687688 }
688689}
689690
690- impl < ' a , A > ListInsertion < A > for IterMut < ' a , A > {
691+ impl < ' a , A > IterMut < ' a , A > {
692+ /// Inserts `elt` just after the element most recently returned by `.next()`.
693+ /// The inserted element does not appear in the iteration.
694+ ///
695+ /// # Examples
696+ ///
697+ /// ```rust
698+ /// use std::collections::DList;
699+ ///
700+ /// let mut list: DList<int> = vec![1, 3, 4].into_iter().collect();
701+ ///
702+ /// {
703+ /// let mut it = list.iter_mut();
704+ /// assert_eq!(it.next().unwrap(), &1);
705+ /// // insert `2` after `1`
706+ /// it.insert_next(2);
707+ /// }
708+ /// {
709+ /// let vec: Vec<int> = list.into_iter().collect();
710+ /// assert_eq!(vec, vec![1i, 2, 3, 4]);
711+ /// }
712+ /// ```
691713 #[ inline]
692- fn insert_next ( & mut self , elt : A ) {
714+ pub fn insert_next ( & mut self , elt : A ) {
693715 self . insert_next_node ( box Node :: new ( elt) )
694716 }
695717
718+ /// Provides a reference to the next element, without changing the iterator.
719+ ///
720+ /// # Examples
721+ ///
722+ /// ```rust
723+ /// use std::collections::DList;
724+ ///
725+ /// let mut list: DList<int> = vec![1, 2, 3].into_iter().collect();
726+ ///
727+ /// let mut it = list.iter_mut();
728+ /// assert_eq!(it.next().unwrap(), &1);
729+ /// assert_eq!(it.peek_next().unwrap(), &2);
730+ /// // We just peeked at 2, so it was not consumed from the iterator.
731+ /// assert_eq!(it.next().unwrap(), &2);
732+ /// ```
696733 #[ inline]
697- fn peek_next ( & mut self ) -> Option < & mut A > {
734+ pub fn peek_next ( & mut self ) -> Option < & mut A > {
698735 if self . nelem == 0 {
699736 return None
700737 }
@@ -796,7 +833,7 @@ mod tests {
796833 use test:: Bencher ;
797834 use test;
798835
799- use super :: { DList , Node , ListInsertion } ;
836+ use super :: { DList , Node } ;
800837
801838 pub fn check_links < T > ( list : & DList < T > ) {
802839 let mut len = 0 u;
0 commit comments