Inserts an element as position `index` in the list, shifting all elements after it to the right.
(&mut self, index: usize, element: T, pool: &mut ListPool<T>)
| 528 | /// Inserts an element as position `index` in the list, shifting all elements after it to the |
| 529 | /// right. |
| 530 | pub fn insert(&mut self, index: usize, element: T, pool: &mut ListPool<T>) { |
| 531 | // Increase size by 1. |
| 532 | self.push(element, pool); |
| 533 | |
| 534 | // Move tail elements. |
| 535 | let seq = self.as_mut_slice(pool); |
| 536 | if index < seq.len() { |
| 537 | let tail = &mut seq[index..]; |
| 538 | for i in (1..tail.len()).rev() { |
| 539 | tail[i] = tail[i - 1]; |
| 540 | } |
| 541 | tail[0] = element; |
| 542 | } else { |
| 543 | debug_assert_eq!(index, seq.len()); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /// Removes the last element from the list. |
| 548 | fn remove_last(&mut self, len: usize, pool: &mut ListPool<T>) { |