@@ -466,7 +466,7 @@ impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap> {
466
466
///
467
467
/// Because the `position` can be invalid, this method returns a
468
468
/// `Result`.
469
- pub fn insert_items_at < I > ( & mut self , items : I , position : Position ) -> Result < ( ) , Error >
469
+ pub fn insert_items_at < I > ( & mut self , position : Position , items : I ) -> Result < ( ) , Error >
470
470
where
471
471
Item : Clone ,
472
472
Gap : Clone ,
@@ -2265,11 +2265,11 @@ mod tests {
2265
2265
2266
2266
// Insert inside the last chunk.
2267
2267
{
2268
- let position_of_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2268
+ let pos_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2269
2269
2270
2270
// Insert 4 elements, so that it overflows the chunk capacity. It's important to
2271
2271
// see whether chunks are correctly updated and linked.
2272
- linked_chunk. insert_items_at ( [ 'w' , 'x' , 'y' , 'z' ] , position_of_e ) ?;
2272
+ linked_chunk. insert_items_at ( pos_e , [ 'w' , 'x' , 'y' , 'z' ] ) ?;
2273
2273
2274
2274
assert_items_eq ! (
2275
2275
linked_chunk,
@@ -2302,8 +2302,8 @@ mod tests {
2302
2302
2303
2303
// Insert inside the first chunk.
2304
2304
{
2305
- let position_of_a = linked_chunk. item_position ( |item| * item == 'a' ) . unwrap ( ) ;
2306
- linked_chunk. insert_items_at ( [ 'l' , 'm' , 'n' , 'o' ] , position_of_a ) ?;
2305
+ let pos_a = linked_chunk. item_position ( |item| * item == 'a' ) . unwrap ( ) ;
2306
+ linked_chunk. insert_items_at ( pos_a , [ 'l' , 'm' , 'n' , 'o' ] ) ?;
2307
2307
2308
2308
assert_items_eq ! (
2309
2309
linked_chunk,
@@ -2336,8 +2336,8 @@ mod tests {
2336
2336
2337
2337
// Insert inside a middle chunk.
2338
2338
{
2339
- let position_of_c = linked_chunk. item_position ( |item| * item == 'c' ) . unwrap ( ) ;
2340
- linked_chunk. insert_items_at ( [ 'r' , 's' ] , position_of_c ) ?;
2339
+ let pos_c = linked_chunk. item_position ( |item| * item == 'c' ) . unwrap ( ) ;
2340
+ linked_chunk. insert_items_at ( pos_c , [ 'r' , 's' ] ) ?;
2341
2341
2342
2342
assert_items_eq ! (
2343
2343
linked_chunk,
@@ -2358,11 +2358,10 @@ mod tests {
2358
2358
2359
2359
// Insert at the end of a chunk.
2360
2360
{
2361
- let position_of_f = linked_chunk. item_position ( |item| * item == 'f' ) . unwrap ( ) ;
2362
- let position_after_f =
2363
- Position ( position_of_f. chunk_identifier ( ) , position_of_f. index ( ) + 1 ) ;
2361
+ let pos_f = linked_chunk. item_position ( |item| * item == 'f' ) . unwrap ( ) ;
2362
+ let pos_f = Position ( pos_f. chunk_identifier ( ) , pos_f. index ( ) + 1 ) ;
2364
2363
2365
- linked_chunk. insert_items_at ( [ 'p' , 'q' ] , position_after_f ) ?;
2364
+ linked_chunk. insert_items_at ( pos_f , [ 'p' , 'q' ] ) ?;
2366
2365
assert_items_eq ! (
2367
2366
linked_chunk,
2368
2367
[ 'l' , 'm' , 'n' ] [ 'o' , 'a' , 'b' ] [ 'r' , 's' , 'c' ] [ 'd' , 'w' , 'x' ] [ 'y' , 'z' , 'e' ] [ 'f' , 'p' , 'q' ]
@@ -2377,7 +2376,7 @@ mod tests {
2377
2376
// Insert in a chunk that does not exist.
2378
2377
{
2379
2378
assert_matches ! (
2380
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 128 ) , 0 ) ) ,
2379
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 128 ) , 0 ) , [ 'u' , 'v' ] , ) ,
2381
2380
Err ( Error :: InvalidChunkIdentifier { identifier: ChunkIdentifier ( 128 ) } )
2382
2381
) ;
2383
2382
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
@@ -2386,7 +2385,7 @@ mod tests {
2386
2385
// Insert in a chunk that exists, but at an item that does not exist.
2387
2386
{
2388
2387
assert_matches ! (
2389
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 0 ) , 128 ) ) ,
2388
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 0 ) , 128 ) , [ 'u' , 'v' ] , ) ,
2390
2389
Err ( Error :: InvalidItemIndex { index: 128 } )
2391
2390
) ;
2392
2391
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
@@ -2411,7 +2410,7 @@ mod tests {
2411
2410
) ;
2412
2411
2413
2412
assert_matches ! (
2414
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 6 ) , 0 ) ) ,
2413
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 6 ) , 0 ) , [ 'u' , 'v' ] , ) ,
2415
2414
Err ( Error :: ChunkIsAGap { identifier: ChunkIdentifier ( 6 ) } )
2416
2415
) ;
2417
2416
}
@@ -2446,11 +2445,11 @@ mod tests {
2446
2445
) ;
2447
2446
2448
2447
// Insert inside the last chunk.
2449
- let position_of_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2448
+ let pos_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2450
2449
2451
2450
// Insert 4 elements, so that it overflows the chunk capacity. It's important to
2452
2451
// see whether chunks are correctly updated and linked.
2453
- linked_chunk. insert_items_at ( [ 'w' , 'x' , 'y' , 'z' ] , position_of_e ) ?;
2452
+ linked_chunk. insert_items_at ( pos_e , [ 'w' , 'x' , 'y' , 'z' ] ) ?;
2454
2453
2455
2454
assert_items_eq ! (
2456
2455
linked_chunk,
@@ -2508,8 +2507,8 @@ mod tests {
2508
2507
) ;
2509
2508
2510
2509
// Insert inside the first chunk.
2511
- let position_of_a = linked_chunk. item_position ( |item| * item == 'a' ) . unwrap ( ) ;
2512
- linked_chunk. insert_items_at ( [ 'l' , 'm' , 'n' , 'o' ] , position_of_a ) ?;
2510
+ let pos_a = linked_chunk. item_position ( |item| * item == 'a' ) . unwrap ( ) ;
2511
+ linked_chunk. insert_items_at ( pos_a , [ 'l' , 'm' , 'n' , 'o' ] ) ?;
2513
2512
2514
2513
assert_items_eq ! (
2515
2514
linked_chunk,
@@ -2572,8 +2571,8 @@ mod tests {
2572
2571
]
2573
2572
) ;
2574
2573
2575
- let position_of_d = linked_chunk. item_position ( |item| * item == 'd' ) . unwrap ( ) ;
2576
- linked_chunk. insert_items_at ( [ 'r' , 's' ] , position_of_d ) ?;
2574
+ let pos_d = linked_chunk. item_position ( |item| * item == 'd' ) . unwrap ( ) ;
2575
+ linked_chunk. insert_items_at ( pos_d , [ 'r' , 's' ] ) ?;
2577
2576
2578
2577
assert_items_eq ! (
2579
2578
linked_chunk,
@@ -2625,11 +2624,10 @@ mod tests {
2625
2624
) ;
2626
2625
2627
2626
// Insert at the end of a chunk.
2628
- let position_of_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2629
- let position_after_e =
2630
- Position ( position_of_e. chunk_identifier ( ) , position_of_e. index ( ) + 1 ) ;
2627
+ let pos_e = linked_chunk. item_position ( |item| * item == 'e' ) . unwrap ( ) ;
2628
+ let pos_after_e = Position ( pos_e. chunk_identifier ( ) , pos_e. index ( ) + 1 ) ;
2631
2629
2632
- linked_chunk. insert_items_at ( [ 'p' , 'q' ] , position_after_e ) ?;
2630
+ linked_chunk. insert_items_at ( pos_after_e , [ 'p' , 'q' ] ) ?;
2633
2631
assert_items_eq ! (
2634
2632
linked_chunk,
2635
2633
[ 'a' , 'b' , 'c' ] [ 'd' , 'e' , 'p' ] [ 'q' ]
@@ -2679,7 +2677,7 @@ mod tests {
2679
2677
// Insert in a chunk that does not exist.
2680
2678
{
2681
2679
assert_matches ! (
2682
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 128 ) , 0 ) ) ,
2680
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 128 ) , 0 ) , [ 'u' , 'v' ] , ) ,
2683
2681
Err ( Error :: InvalidChunkIdentifier { identifier: ChunkIdentifier ( 128 ) } )
2684
2682
) ;
2685
2683
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
@@ -2688,7 +2686,7 @@ mod tests {
2688
2686
// Insert in a chunk that exists, but at an item that does not exist.
2689
2687
{
2690
2688
assert_matches ! (
2691
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 0 ) , 128 ) ) ,
2689
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 0 ) , 128 ) , [ 'u' , 'v' ] , ) ,
2692
2690
Err ( Error :: InvalidItemIndex { index: 128 } )
2693
2691
) ;
2694
2692
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
@@ -2697,7 +2695,7 @@ mod tests {
2697
2695
// Insert in a gap.
2698
2696
{
2699
2697
assert_matches ! (
2700
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 1 ) , 0 ) ) ,
2698
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 1 ) , 0 ) , [ 'u' , 'v' ] , ) ,
2701
2699
Err ( Error :: ChunkIsAGap { identifier: ChunkIdentifier ( 1 ) } )
2702
2700
) ;
2703
2701
}
@@ -3039,7 +3037,7 @@ mod tests {
3039
3037
// Insert in a chunk that does not exist.
3040
3038
{
3041
3039
assert_matches ! (
3042
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 128 ) , 0 ) ) ,
3040
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 128 ) , 0 ) , [ 'u' , 'v' ] , ) ,
3043
3041
Err ( Error :: InvalidChunkIdentifier { identifier: ChunkIdentifier ( 128 ) } )
3044
3042
) ;
3045
3043
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
@@ -3048,7 +3046,7 @@ mod tests {
3048
3046
// Insert in a chunk that exists, but at an item that does not exist.
3049
3047
{
3050
3048
assert_matches ! (
3051
- linked_chunk. insert_items_at( [ 'u' , 'v' ] , Position ( ChunkIdentifier ( 0 ) , 128 ) ) ,
3049
+ linked_chunk. insert_items_at( Position ( ChunkIdentifier ( 0 ) , 128 ) , [ 'u' , 'v' ] , ) ,
3052
3050
Err ( Error :: InvalidItemIndex { index: 128 } )
3053
3051
) ;
3054
3052
assert ! ( linked_chunk. updates( ) . unwrap( ) . take( ) . is_empty( ) ) ;
0 commit comments