@@ -17,10 +17,7 @@ use core::{
1717 ptr, slice,
1818} ;
1919
20- use crate :: {
21- storage:: { OwnedStorage , Storage , ViewStorage } ,
22- vec:: { Vec , VecInner } ,
23- } ;
20+ use crate :: vec:: { OwnedVecStorage , Vec , VecInner , VecStorage , ViewVecStorage } ;
2421
2522/// Min-heap
2623pub enum Min { }
@@ -54,11 +51,11 @@ mod private {
5451impl private:: Sealed for Max { }
5552impl private:: Sealed for Min { }
5653
57- /// Base struct for [`BinaryHeap`] and [`BinaryHeapView`], generic over the [`Storage `].
54+ /// Base struct for [`BinaryHeap`] and [`BinaryHeapView`], generic over the [`VecStorage `].
5855///
5956/// In most cases you should use [`BinaryHeap`] or [`BinaryHeapView`] directly. Only use this
6057/// struct if you want to write code that's generic over both.
61- pub struct BinaryHeapInner < T , K , S : Storage > {
58+ pub struct BinaryHeapInner < T , K , S : VecStorage < T > + ? Sized > {
6259 pub ( crate ) _kind : PhantomData < K > ,
6360 pub ( crate ) data : VecInner < T , S > ,
6461}
@@ -109,7 +106,7 @@ pub struct BinaryHeapInner<T, K, S: Storage> {
109106/// // The heap should now be empty.
110107/// assert!(heap.is_empty())
111108/// ```
112- pub type BinaryHeap < T , K , const N : usize > = BinaryHeapInner < T , K , OwnedStorage < N > > ;
109+ pub type BinaryHeap < T , K , const N : usize > = BinaryHeapInner < T , K , OwnedVecStorage < T , N > > ;
113110
114111/// A priority queue implemented with a binary heap.
115112///
@@ -158,7 +155,7 @@ pub type BinaryHeap<T, K, const N: usize> = BinaryHeapInner<T, K, OwnedStorage<N
158155/// // The heap should now be empty.
159156/// assert!(heap.is_empty())
160157/// ```
161- pub type BinaryHeapView < T , K > = BinaryHeapInner < T , K , ViewStorage > ;
158+ pub type BinaryHeapView < T , K > = BinaryHeapInner < T , K , ViewVecStorage < T > > ;
162159
163160impl < T , K , const N : usize > BinaryHeap < T , K , N > {
164161 /* Constructors */
@@ -198,7 +195,7 @@ impl<T, K, const N: usize> BinaryHeap<T, K, N> {
198195 }
199196}
200197
201- impl < T , K , S : Storage > BinaryHeapInner < T , K , S >
198+ impl < T , K , S : VecStorage < T > + ? Sized > BinaryHeapInner < T , K , S >
202199where
203200 T : Ord ,
204201 K : Kind ,
@@ -519,7 +516,7 @@ pub struct PeekMutInner<'a, T, K, S>
519516where
520517 T : Ord ,
521518 K : Kind ,
522- S : Storage ,
519+ S : VecStorage < T > + ? Sized ,
523520{
524521 heap : & ' a mut BinaryHeapInner < T , K , S > ,
525522 sift : bool ,
@@ -530,20 +527,20 @@ where
530527///
531528/// This `struct` is created by [`BinaryHeap::peek_mut`].
532529/// See its documentation for more.
533- pub type PeekMut < ' a , T , K , const N : usize > = PeekMutInner < ' a , T , K , OwnedStorage < N > > ;
530+ pub type PeekMut < ' a , T , K , const N : usize > = PeekMutInner < ' a , T , K , OwnedVecStorage < T , N > > ;
534531
535532/// Structure wrapping a mutable reference to the greatest item on a
536533/// `BinaryHeap`.
537534///
538535/// This `struct` is created by [`BinaryHeapView::peek_mut`].
539536/// See its documentation for more.
540- pub type PeekMutView < ' a , T , K > = PeekMutInner < ' a , T , K , ViewStorage > ;
537+ pub type PeekMutView < ' a , T , K > = PeekMutInner < ' a , T , K , ViewVecStorage < T > > ;
541538
542539impl < T , K , S > Drop for PeekMutInner < ' _ , T , K , S >
543540where
544541 T : Ord ,
545542 K : Kind ,
546- S : Storage ,
543+ S : VecStorage < T > + ? Sized ,
547544{
548545 fn drop ( & mut self ) {
549546 if self . sift {
@@ -556,7 +553,7 @@ impl<T, K, S> Deref for PeekMutInner<'_, T, K, S>
556553where
557554 T : Ord ,
558555 K : Kind ,
559- S : Storage ,
556+ S : VecStorage < T > + ? Sized ,
560557{
561558 type Target = T ;
562559 fn deref ( & self ) -> & T {
@@ -570,7 +567,7 @@ impl<T, K, S> DerefMut for PeekMutInner<'_, T, K, S>
570567where
571568 T : Ord ,
572569 K : Kind ,
573- S : Storage ,
570+ S : VecStorage < T > + ? Sized ,
574571{
575572 fn deref_mut ( & mut self ) -> & mut T {
576573 debug_assert ! ( !self . heap. is_empty( ) ) ;
@@ -583,7 +580,7 @@ impl<'a, T, K, S> PeekMutInner<'a, T, K, S>
583580where
584581 T : Ord ,
585582 K : Kind ,
586- S : Storage ,
583+ S : VecStorage < T > + ? Sized ,
587584{
588585 /// Removes the peeked value from the heap and returns it.
589586 pub fn pop ( mut this : PeekMutInner < ' a , T , K , S > ) -> T {
@@ -631,7 +628,7 @@ impl<T, K, S> fmt::Debug for BinaryHeapInner<T, K, S>
631628where
632629 K : Kind ,
633630 T : Ord + fmt:: Debug ,
634- S : Storage ,
631+ S : VecStorage < T > + ? Sized ,
635632{
636633 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
637634 f. debug_list ( ) . entries ( self . iter ( ) ) . finish ( )
@@ -642,7 +639,7 @@ impl<'a, T, K, S> IntoIterator for &'a BinaryHeapInner<T, K, S>
642639where
643640 K : Kind ,
644641 T : Ord ,
645- S : Storage ,
642+ S : VecStorage < T > + ? Sized ,
646643{
647644 type Item = & ' a T ;
648645 type IntoIter = slice:: Iter < ' a , T > ;
@@ -656,7 +653,7 @@ where
656653mod tests {
657654 use static_assertions:: assert_not_impl_any;
658655
659- use super :: { BinaryHeap , Max , Min } ;
656+ use super :: { BinaryHeap , BinaryHeapView , Max , Min } ;
660657
661658 // Ensure a `BinaryHeap` containing `!Send` values stays `!Send` itself.
662659 assert_not_impl_any ! ( BinaryHeap <* const ( ) , Max , 4 >: Send ) ;
@@ -829,4 +826,13 @@ mod tests {
829826 assert_eq ! ( heap. pop( ) , Some ( 1 ) ) ;
830827 assert_eq ! ( heap. pop( ) , None ) ;
831828 }
829+
830+ fn _test_variance < ' a : ' b , ' b > ( x : BinaryHeap < & ' a ( ) , Max , 42 > ) -> BinaryHeap < & ' b ( ) , Max , 42 > {
831+ x
832+ }
833+ fn _test_variance_view < ' a : ' b , ' b , ' c > (
834+ x : & ' c BinaryHeapView < & ' a ( ) , Max > ,
835+ ) -> & ' c BinaryHeapView < & ' b ( ) , Max > {
836+ x
837+ }
832838}
0 commit comments