@@ -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 ,
@@ -539,7 +536,7 @@ pub struct PeekMutInner<'a, T, K, S>
539536where
540537 T : Ord ,
541538 K : Kind ,
542- S : Storage ,
539+ S : VecStorage < T > + ? Sized ,
543540{
544541 heap : & ' a mut BinaryHeapInner < T , K , S > ,
545542 sift : bool ,
@@ -550,20 +547,20 @@ where
550547///
551548/// This `struct` is created by [`BinaryHeap::peek_mut`].
552549/// See its documentation for more.
553- pub type PeekMut < ' a , T , K , const N : usize > = PeekMutInner < ' a , T , K , OwnedStorage < N > > ;
550+ pub type PeekMut < ' a , T , K , const N : usize > = PeekMutInner < ' a , T , K , OwnedVecStorage < T , N > > ;
554551
555552/// Structure wrapping a mutable reference to the greatest item on a
556553/// `BinaryHeap`.
557554///
558555/// This `struct` is created by [`BinaryHeapView::peek_mut`].
559556/// See its documentation for more.
560- pub type PeekMutView < ' a , T , K > = PeekMutInner < ' a , T , K , ViewStorage > ;
557+ pub type PeekMutView < ' a , T , K > = PeekMutInner < ' a , T , K , ViewVecStorage < T > > ;
561558
562559impl < T , K , S > Drop for PeekMutInner < ' _ , T , K , S >
563560where
564561 T : Ord ,
565562 K : Kind ,
566- S : Storage ,
563+ S : VecStorage < T > + ? Sized ,
567564{
568565 fn drop ( & mut self ) {
569566 if self . sift {
@@ -576,7 +573,7 @@ impl<T, K, S> Deref for PeekMutInner<'_, T, K, S>
576573where
577574 T : Ord ,
578575 K : Kind ,
579- S : Storage ,
576+ S : VecStorage < T > + ? Sized ,
580577{
581578 type Target = T ;
582579 fn deref ( & self ) -> & T {
@@ -590,7 +587,7 @@ impl<T, K, S> DerefMut for PeekMutInner<'_, T, K, S>
590587where
591588 T : Ord ,
592589 K : Kind ,
593- S : Storage ,
590+ S : VecStorage < T > + ? Sized ,
594591{
595592 fn deref_mut ( & mut self ) -> & mut T {
596593 debug_assert ! ( !self . heap. is_empty( ) ) ;
@@ -603,7 +600,7 @@ impl<'a, T, K, S> PeekMutInner<'a, T, K, S>
603600where
604601 T : Ord ,
605602 K : Kind ,
606- S : Storage ,
603+ S : VecStorage < T > + ? Sized ,
607604{
608605 /// Removes the peeked value from the heap and returns it.
609606 pub fn pop ( mut this : PeekMutInner < ' a , T , K , S > ) -> T {
@@ -651,7 +648,7 @@ impl<T, K, S> fmt::Debug for BinaryHeapInner<T, K, S>
651648where
652649 K : Kind ,
653650 T : Ord + fmt:: Debug ,
654- S : Storage ,
651+ S : VecStorage < T > + ? Sized ,
655652{
656653 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
657654 f. debug_list ( ) . entries ( self . iter ( ) ) . finish ( )
@@ -662,7 +659,7 @@ impl<'a, T, K, S> IntoIterator for &'a BinaryHeapInner<T, K, S>
662659where
663660 K : Kind ,
664661 T : Ord ,
665- S : Storage ,
662+ S : VecStorage < T > + ? Sized ,
666663{
667664 type Item = & ' a T ;
668665 type IntoIter = slice:: Iter < ' a , T > ;
@@ -676,7 +673,7 @@ where
676673mod tests {
677674 use static_assertions:: assert_not_impl_any;
678675
679- use super :: { BinaryHeap , Max , Min } ;
676+ use super :: { BinaryHeap , BinaryHeapView , Max , Min } ;
680677
681678 // Ensure a `BinaryHeap` containing `!Send` values stays `!Send` itself.
682679 assert_not_impl_any ! ( BinaryHeap <* const ( ) , Max , 4 >: Send ) ;
@@ -849,4 +846,13 @@ mod tests {
849846 assert_eq ! ( heap. pop( ) , Some ( 1 ) ) ;
850847 assert_eq ! ( heap. pop( ) , None ) ;
851848 }
849+
850+ fn _test_variance < ' a : ' b , ' b > ( x : BinaryHeap < & ' a ( ) , Max , 42 > ) -> BinaryHeap < & ' b ( ) , Max , 42 > {
851+ x
852+ }
853+ fn _test_variance_view < ' a : ' b , ' b , ' c > (
854+ x : & ' c BinaryHeapView < & ' a ( ) , Max > ,
855+ ) -> & ' c BinaryHeapView < & ' b ( ) , Max > {
856+ x
857+ }
852858}
0 commit comments