@@ -1132,7 +1132,7 @@ pub struct Cursor<'a, T: 'a> {
11321132#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
11331133impl < T : fmt:: Debug > fmt:: Debug for Cursor < ' _ , T > {
11341134 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1135- f. debug_tuple ( "Cursor" ) . field ( & self . list ) . field ( & self . index ) . finish ( )
1135+ f. debug_tuple ( "Cursor" ) . field ( & self . list ) . field ( & self . index ( ) ) . finish ( )
11361136 }
11371137}
11381138
@@ -1158,11 +1158,21 @@ pub struct CursorMut<'a, T: 'a> {
11581158#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
11591159impl < T : fmt:: Debug > fmt:: Debug for CursorMut < ' _ , T > {
11601160 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1161- f. debug_tuple ( "CursorMut" ) . field ( & self . list ) . field ( & self . index ) . finish ( )
1161+ f. debug_tuple ( "CursorMut" ) . field ( & self . list ) . field ( & self . index ( ) ) . finish ( )
11621162 }
11631163}
11641164
11651165impl < ' a , T > Cursor < ' a , T > {
1166+ /// Returns the cursor position index within the `LinkedList`.
1167+ ///
1168+ /// This returns `None` if the cursor is currently pointing to the
1169+ /// "ghost" non-element.
1170+ #[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1171+ pub fn index ( & self ) -> Option < usize > {
1172+ let _ = self . current ?;
1173+ Some ( self . index )
1174+ }
1175+
11661176 /// Moves the cursor to the next element of the `LinkedList`.
11671177 ///
11681178 /// If the cursor is pointing to the "ghost" non-element then this will move it to
@@ -1250,6 +1260,16 @@ impl<'a, T> Cursor<'a, T> {
12501260}
12511261
12521262impl < ' a , T > CursorMut < ' a , T > {
1263+ /// Returns the cursor position index within the `LinkedList`.
1264+ ///
1265+ /// This returns `None` if the cursor is currently pointing to the
1266+ /// "ghost" non-element.
1267+ #[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1268+ pub fn index ( & self ) -> Option < usize > {
1269+ let _ = self . current ?;
1270+ Some ( self . index )
1271+ }
1272+
12531273 /// Moves the cursor to the next element of the `LinkedList`.
12541274 ///
12551275 /// If the cursor is pointing to the "ghost" non-element then this will move it to
@@ -1456,6 +1476,7 @@ impl<'a, T> CursorMut<'a, T> {
14561476 #[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
14571477 pub fn split_after ( self ) -> LinkedList < T > {
14581478 let split_off_idx = if self . index == self . list . len { 0 } else { self . index + 1 } ;
1479+ // no need to update `self.index` because the cursor is consumed.
14591480 unsafe { self . list . split_off_after_node ( self . current , split_off_idx) }
14601481 }
14611482
@@ -1468,6 +1489,7 @@ impl<'a, T> CursorMut<'a, T> {
14681489 #[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
14691490 pub fn split_before ( self ) -> LinkedList < T > {
14701491 let split_off_idx = self . index ;
1492+ // no need to update `self.index` because the cursor is consumed.
14711493 unsafe { self . list . split_off_before_node ( self . current , split_off_idx) }
14721494 }
14731495}
0 commit comments