1- #![ feature( linked_list_extras ) ]
1+ #![ feature( linked_list_cursors ) ]
22use std:: collections:: LinkedList ;
33
44fn list_from < T : Clone > ( v : & [ T ] ) -> LinkedList < T > {
@@ -9,25 +9,27 @@ fn main() {
99 let mut m = list_from ( & [ 0 , 2 , 4 , 6 , 8 ] ) ;
1010 let len = m. len ( ) ;
1111 {
12- let mut it = m. iter_mut ( ) ;
13- it. insert_next ( -2 ) ;
12+ let mut it = m. cursor_front_mut ( ) ;
13+ it. insert_before ( -2 ) ;
1414 loop {
15- match it. next ( ) {
15+ match it. current ( ) . copied ( ) {
1616 None => break ,
1717 Some ( elt) => {
18- it. insert_next ( * elt + 1 ) ;
1918 match it. peek_next ( ) {
20- Some ( x) => assert_eq ! ( * x, * elt + 2 ) ,
21- None => assert_eq ! ( 8 , * elt) ,
19+ Some ( x) => assert_eq ! ( * x, elt + 2 ) ,
20+ None => assert_eq ! ( 8 , elt) ,
2221 }
22+ it. insert_after ( elt + 1 ) ;
23+ it. move_next ( ) ; // Move by 2 to skip the one we inserted.
24+ it. move_next ( ) ;
2325 }
2426 }
2527 }
26- it. insert_next ( 0 ) ;
27- it. insert_next ( 1 ) ;
28+ it. insert_before ( 99 ) ;
29+ it. insert_after ( - 10 ) ;
2830 }
2931
3032 assert_eq ! ( m. len( ) , 3 + len * 2 ) ;
3133 assert_eq ! ( m. into_iter( ) . collect:: <Vec <_>>( ) ,
32- [ -2 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 1 ] ) ;
34+ [ -10 , - 2 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 99 ] ) ;
3335}
0 commit comments