@@ -653,6 +653,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> {
653
653
impl < ' a , A > ExactSizeIterator < & ' a mut A > for IterMut < ' a , A > { }
654
654
655
655
/// Allows mutating a `DList` while iterating.
656
+ #[ deprecated = "Trait is deprecated, use inherent methods on the iterator instead" ]
656
657
pub trait ListInsertion < A > {
657
658
/// Inserts `elt` just after to the element most recently returned by
658
659
/// `.next()`
@@ -687,14 +688,50 @@ impl<'a, A> IterMut<'a, A> {
687
688
}
688
689
}
689
690
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
+ /// ```
691
713
#[ inline]
692
- fn insert_next ( & mut self , elt : A ) {
714
+ pub fn insert_next ( & mut self , elt : A ) {
693
715
self . insert_next_node ( box Node :: new ( elt) )
694
716
}
695
717
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
+ /// ```
696
733
#[ inline]
697
- fn peek_next ( & mut self ) -> Option < & mut A > {
734
+ pub fn peek_next ( & mut self ) -> Option < & mut A > {
698
735
if self . nelem == 0 {
699
736
return None
700
737
}
@@ -796,7 +833,7 @@ mod tests {
796
833
use test:: Bencher ;
797
834
use test;
798
835
799
- use super :: { DList , Node , ListInsertion } ;
836
+ use super :: { DList , Node } ;
800
837
801
838
pub fn check_links < T > ( list : & DList < T > ) {
802
839
let mut len = 0 u;
0 commit comments