@@ -17,7 +17,7 @@ use marker;
1717use mem:: { align_of, size_of} ;
1818use mem;
1919use ops:: { Deref , DerefMut } ;
20- use ptr:: { self , Unique } ;
20+ use ptr:: { self , Unique , Shared } ;
2121
2222use self :: BucketState :: * ;
2323
@@ -754,7 +754,8 @@ impl<K, V> RawTable<K, V> {
754754 hashes_end : hashes_end,
755755 marker : marker:: PhantomData ,
756756 } ,
757- table : self ,
757+ table : unsafe { Shared :: new ( self ) } ,
758+ marker : marker:: PhantomData ,
758759 }
759760 }
760761
@@ -897,8 +898,9 @@ unsafe impl<K: Send, V: Send> Send for IntoIter<K, V> {}
897898
898899/// Iterator over the entries in a table, clearing the table.
899900pub struct Drain < ' a , K : ' a , V : ' a > {
900- table : & ' a mut RawTable < K , V > ,
901+ table : Shared < RawTable < K , V > > ,
901902 iter : RawBuckets < ' static , K , V > ,
903+ marker : marker:: PhantomData < & ' a RawTable < K , V > > ,
902904}
903905
904906unsafe impl < ' a , K : Sync , V : Sync > Sync for Drain < ' a , K , V > { }
@@ -973,8 +975,8 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
973975 #[ inline]
974976 fn next ( & mut self ) -> Option < ( SafeHash , K , V ) > {
975977 self . iter . next ( ) . map ( |bucket| {
976- self . table . size -= 1 ;
977978 unsafe {
979+ ( * * self . table ) . size -= 1 ;
978980 ( SafeHash { hash : ptr:: replace ( bucket. hash , EMPTY_BUCKET ) } ,
979981 ptr:: read ( bucket. key ) ,
980982 ptr:: read ( bucket. val ) )
@@ -983,13 +985,15 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
983985 }
984986
985987 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
986- let size = self . table . size ( ) ;
988+ let size = unsafe { ( * * self . table ) . size ( ) } ;
987989 ( size, Some ( size) )
988990 }
989991}
990992impl < ' a , K , V > ExactSizeIterator for Drain < ' a , K , V > {
991993 fn len ( & self ) -> usize {
992- self . table . size ( )
994+ unsafe {
995+ ( * * self . table ) . size ( )
996+ }
993997 }
994998}
995999
0 commit comments