| 292 | } |
| 293 | |
| 294 | fn drain_range(&mut self, start: usize, end: usize) -> Drain<'_, T> { |
| 295 | let len = self.len(); |
| 296 | |
| 297 | // bounds check happens here (before length is changed!) |
| 298 | let range_slice: *const _ = &self[start..end]; |
| 299 | |
| 300 | // Calling `set_len` creates a fresh and thus unique mutable references, making all |
| 301 | // older aliases we created invalid. So we cannot call that function. |
| 302 | self.len = start; |
| 303 | |
| 304 | unsafe { |
| 305 | Drain { |
| 306 | tail_start: end, |
| 307 | tail_len: len - end, |
| 308 | iter: (*range_slice).iter(), |
| 309 | vec: ptr::NonNull::from(self), |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /// Return a slice containing all elements of the vector. |
| 315 | pub fn as_slice(&self) -> &[T] { |