2 use core::slice::{self};
4 // A helper struct for in-place iteration that drops the destination slice of iteration,
5 // i.e. the head. The source slice (the tail) is dropped by IntoIter.
6 pub(super) struct InPlaceDrop<T> {
7 pub(super) inner: *mut T,
8 pub(super) dst: *mut T,
11 impl<T> InPlaceDrop<T> {
12 fn len(&self) -> usize {
13 unsafe { self.dst.sub_ptr(self.inner) }
17 impl<T> Drop for InPlaceDrop<T> {
21 ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len()));
26 // A helper struct for in-place collection that drops the destination allocation and elements,
27 // to avoid leaking them if some other destructor panics.
28 pub(super) struct InPlaceDstBufDrop<T> {
29 pub(super) ptr: *mut T,
30 pub(super) len: usize,
31 pub(super) cap: usize,
34 impl<T> Drop for InPlaceDstBufDrop<T> {
37 unsafe { super::Vec::from_raw_parts(self.ptr, self.len, self.cap) };