1
- #![ feature( linked_list_extras ) ]
1
+ #![ feature( linked_list_cursors ) ]
2
2
use std:: collections:: LinkedList ;
3
3
4
4
fn list_from < T : Clone > ( v : & [ T ] ) -> LinkedList < T > {
@@ -9,25 +9,27 @@ fn main() {
9
9
let mut m = list_from ( & [ 0 , 2 , 4 , 6 , 8 ] ) ;
10
10
let len = m. len ( ) ;
11
11
{
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 ) ;
14
14
loop {
15
- match it. next ( ) {
15
+ match it. current ( ) . copied ( ) {
16
16
None => break ,
17
17
Some ( elt) => {
18
- it. insert_next ( * elt + 1 ) ;
19
18
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) ,
22
21
}
22
+ it. insert_after ( elt + 1 ) ;
23
+ it. move_next ( ) ; // Move by 2 to skip the one we inserted.
24
+ it. move_next ( ) ;
23
25
}
24
26
}
25
27
}
26
- it. insert_next ( 0 ) ;
27
- it. insert_next ( 1 ) ;
28
+ it. insert_before ( 99 ) ;
29
+ it. insert_after ( - 10 ) ;
28
30
}
29
31
30
32
assert_eq ! ( m. len( ) , 3 + len * 2 ) ;
31
33
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 ] ) ;
33
35
}
0 commit comments