@@ -74,7 +74,7 @@ pub enum Max {}
74
74
75
75
pub struct BinaryHeap < T , K , const N : usize > {
76
76
pub ( crate ) _kind : PhantomData < K > ,
77
- pub ( crate ) data : Vec < T , N > ,
77
+ pub ( crate ) data : ManuallyDrop < Vec < T , N > > ,
78
78
}
79
79
80
80
impl < T , K , const N : usize > BinaryHeap < T , K , N > {
@@ -94,7 +94,7 @@ impl<T, K, const N: usize> BinaryHeap<T, K, N> {
94
94
pub const fn new ( ) -> Self {
95
95
Self {
96
96
_kind : PhantomData ,
97
- data : Vec :: new ( ) ,
97
+ data : ManuallyDrop :: new ( Vec :: new ( ) ) ,
98
98
}
99
99
}
100
100
}
@@ -310,6 +310,14 @@ where
310
310
self . sift_up ( 0 , old_len) ;
311
311
}
312
312
313
+ /// Returns the underlying ```Vec<T,N>```. Order is arbitrary and time is O(1).
314
+ pub fn into_vec ( self ) -> Vec < T , N > {
315
+ // prevents dropping self.data at the end of this fn
316
+ let mut dropless_heap = ManuallyDrop :: new ( self ) ;
317
+ // https://users.rust-lang.org/t/moving-out-of-a-type-implementing-drop/38225/5
318
+ unsafe { ManuallyDrop :: take ( & mut dropless_heap. data ) }
319
+ }
320
+
313
321
/* Private API */
314
322
fn sift_down_to_bottom ( & mut self , mut pos : usize ) {
315
323
let end = self . len ( ) ;
0 commit comments