@@ -367,7 +367,15 @@ impl<Item, Gap, const CAP: usize> LinkedChunk<Item, Gap, CAP> {
367
367
/// It iterates from the last to the first chunk.
368
368
pub fn rchunks ( & self ) -> LinkedChunkIterBackward < ' _ , Item , Gap , CAP > {
369
369
self . rchunks_from ( self . latest_chunk ( ) . identifier ( ) )
370
- . expect ( "`iter_chunks_from` cannot fail because at least one empty chunk must exist" )
370
+ . expect ( "`rchunks_from` cannot fail because at least one empty chunk must exist" )
371
+ }
372
+
373
+ /// Iterate over the chunks, forward.
374
+ ///
375
+ /// It iterates from the first to the last chunk.
376
+ pub fn chunks ( & self ) -> LinkedChunkIter < ' _ , Item , Gap , CAP > {
377
+ self . chunks_from ( ChunkIdentifierGenerator :: FIRST_IDENTIFIER )
378
+ . expect ( "`chunks_from` cannot fail because at least one empty chunk must exist" )
371
379
}
372
380
373
381
/// Iterate over the chunks, starting from `identifier`, backward.
@@ -403,7 +411,7 @@ impl<Item, Gap, const CAP: usize> LinkedChunk<Item, Gap, CAP> {
403
411
/// It iterates from the last to the first item.
404
412
pub fn ritems ( & self ) -> impl Iterator < Item = ( ItemPosition , & Item ) > {
405
413
self . ritems_from ( self . latest_chunk ( ) . identifier ( ) . to_last_item_position ( ) )
406
- . expect ( "`iter_items_from ` cannot fail because at least one empty chunk must exist" )
414
+ . expect ( "`ritems_from ` cannot fail because at least one empty chunk must exist" )
407
415
}
408
416
409
417
/// Iterate over the items, forward.
@@ -1117,6 +1125,40 @@ mod tests {
1117
1125
assert_matches ! ( iterator. next( ) , None ) ;
1118
1126
}
1119
1127
1128
+ #[ test]
1129
+ fn test_chunks ( ) {
1130
+ let mut linked_chunk = LinkedChunk :: < char , ( ) , 2 > :: new ( ) ;
1131
+ linked_chunk. push_items_back ( [ 'a' , 'b' ] ) ;
1132
+ linked_chunk. push_gap_back ( ( ) ) ;
1133
+ linked_chunk. push_items_back ( [ 'c' , 'd' , 'e' ] ) ;
1134
+
1135
+ let mut iterator = linked_chunk. chunks ( ) ;
1136
+
1137
+ assert_matches ! (
1138
+ iterator. next( ) ,
1139
+ Some ( Chunk { identifier: ChunkIdentifier ( 0 ) , content: ChunkContent :: Items ( items) , .. } ) => {
1140
+ assert_eq!( items, & [ 'a' , 'b' ] ) ;
1141
+ }
1142
+ ) ;
1143
+ assert_matches ! (
1144
+ iterator. next( ) ,
1145
+ Some ( Chunk { identifier: ChunkIdentifier ( 1 ) , content: ChunkContent :: Gap ( ..) , .. } )
1146
+ ) ;
1147
+ assert_matches ! (
1148
+ iterator. next( ) ,
1149
+ Some ( Chunk { identifier: ChunkIdentifier ( 2 ) , content: ChunkContent :: Items ( items) , .. } ) => {
1150
+ assert_eq!( items, & [ 'c' , 'd' ] ) ;
1151
+ }
1152
+ ) ;
1153
+ assert_matches ! (
1154
+ iterator. next( ) ,
1155
+ Some ( Chunk { identifier: ChunkIdentifier ( 3 ) , content: ChunkContent :: Items ( items) , .. } ) => {
1156
+ assert_eq!( items, & [ 'e' ] ) ;
1157
+ }
1158
+ ) ;
1159
+ assert_matches ! ( iterator. next( ) , None ) ;
1160
+ }
1161
+
1120
1162
#[ test]
1121
1163
fn test_rchunks_from ( ) -> Result < ( ) , LinkedChunkError > {
1122
1164
let mut linked_chunk = LinkedChunk :: < char , ( ) , 2 > :: new ( ) ;
0 commit comments