Copies a slice from an entity list in the same pool to a position in this one. Will panic if `self` is the same list as `other`.
(
&mut self,
other: &Self,
slice: impl core::ops::RangeBounds<usize>,
index: usize,
pool: &mut ListPool<T>,
)
| 487 | /// |
| 488 | /// Will panic if `self` is the same list as `other`. |
| 489 | pub fn copy_from( |
| 490 | &mut self, |
| 491 | other: &Self, |
| 492 | slice: impl core::ops::RangeBounds<usize>, |
| 493 | index: usize, |
| 494 | pool: &mut ListPool<T>, |
| 495 | ) { |
| 496 | assert!( |
| 497 | index <= self.len(pool), |
| 498 | "attempted to copy a slice out of bounds of `self`" |
| 499 | ); |
| 500 | assert_ne!( |
| 501 | self.index, other.index, |
| 502 | "cannot copy within one `EntityList`" |
| 503 | ); |
| 504 | |
| 505 | let (other_index, other_len) = (other.index, other.len(pool)); |
| 506 | |
| 507 | let start = match slice.start_bound() { |
| 508 | core::ops::Bound::Included(&x) => x, |
| 509 | core::ops::Bound::Excluded(&x) => x + 1, |
| 510 | core::ops::Bound::Unbounded => 0, |
| 511 | } + other_index as usize; |
| 512 | let end = match slice.end_bound() { |
| 513 | core::ops::Bound::Included(&x) => x + 1, |
| 514 | core::ops::Bound::Excluded(&x) => x, |
| 515 | core::ops::Bound::Unbounded => other_len, |
| 516 | } + other_index as usize; |
| 517 | let count = end - start; |
| 518 | assert!( |
| 519 | count <= other_len, |
| 520 | "attempted to copy a slice from out of bounds of `other`" |
| 521 | ); |
| 522 | |
| 523 | self.grow_at(index, count, pool); |
| 524 | pool.data |
| 525 | .copy_within(start..end, index + self.index as usize); |
| 526 | } |
| 527 | |
| 528 | /// Inserts an element as position `index` in the list, shifting all elements after it to the |
| 529 | /// right. |