@@ -1132,7 +1132,7 @@ pub struct Cursor<'a, T: 'a> {
1132
1132
#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1133
1133
impl < T : fmt:: Debug > fmt:: Debug for Cursor < ' _ , T > {
1134
1134
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 ( )
1136
1136
}
1137
1137
}
1138
1138
@@ -1158,11 +1158,21 @@ pub struct CursorMut<'a, T: 'a> {
1158
1158
#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1159
1159
impl < T : fmt:: Debug > fmt:: Debug for CursorMut < ' _ , T > {
1160
1160
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 ( )
1162
1162
}
1163
1163
}
1164
1164
1165
1165
impl < ' 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
+
1166
1176
/// Moves the cursor to the next element of the `LinkedList`.
1167
1177
///
1168
1178
/// 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> {
1250
1260
}
1251
1261
1252
1262
impl < ' 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
+
1253
1273
/// Moves the cursor to the next element of the `LinkedList`.
1254
1274
///
1255
1275
/// 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> {
1456
1476
#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1457
1477
pub fn split_after ( self ) -> LinkedList < T > {
1458
1478
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.
1459
1480
unsafe { self . list . split_off_after_node ( self . current , split_off_idx) }
1460
1481
}
1461
1482
@@ -1468,6 +1489,7 @@ impl<'a, T> CursorMut<'a, T> {
1468
1489
#[ unstable( feature = "linked_list_cursors" , issue = "58533" ) ]
1469
1490
pub fn split_before ( self ) -> LinkedList < T > {
1470
1491
let split_off_idx = self . index ;
1492
+ // no need to update `self.index` because the cursor is consumed.
1471
1493
unsafe { self . list . split_off_before_node ( self . current , split_off_idx) }
1472
1494
}
1473
1495
}
0 commit comments