make 'into_vec' just using 'self.data'

This commit is contained in:
Logan Dimond 2022-05-14 15:47:44 -04:00
parent 338323b7f9
commit 472a839f41

View File

@ -100,7 +100,7 @@ impl private::Sealed for Min {}
pub struct BinaryHeap<T, K, const N: usize> {
pub(crate) _kind: PhantomData<K>,
pub(crate) data: ManuallyDrop<Vec<T, N>>,
pub(crate) data: Vec<T, N>,
}
impl<T, K, const N: usize> BinaryHeap<T, K, N> {
@ -120,7 +120,7 @@ impl<T, K, const N: usize> BinaryHeap<T, K, N> {
pub const fn new() -> Self {
Self {
_kind: PhantomData,
data: ManuallyDrop::new(Vec::new()),
data: Vec::new(),
}
}
}
@ -338,10 +338,7 @@ where
/// Returns the underlying ```Vec<T,N>```. Order is arbitrary and time is O(1).
pub fn into_vec(self) -> Vec<T, N> {
// prevents dropping self.data at the end of this fn
let mut dropless_heap = ManuallyDrop::new(self);
// https://users.rust-lang.org/t/moving-out-of-a-type-implementing-drop/38225/5
unsafe { ManuallyDrop::take(&mut dropless_heap.data) }
self.data
}
/* Private API */