@@ -217,20 +217,30 @@ impl<K, V, M> Deref for FullBucket<K, V, M> where M: Deref<Target=RawTable<K, V>
217
217
}
218
218
}
219
219
220
- impl < K , V , M > DerefMut for FullBucket < K , V , M > where M : DerefMut < Target =RawTable < K , V > > {
221
- fn deref_mut ( & mut self ) -> & mut RawTable < K , V > {
222
- & mut self . table
220
+ /// `Put` is implemented for types which provide access to a table and cannot be invalidated
221
+ /// by filling a bucket. A similar implementation for `Take` is possible.
222
+ pub trait Put < K , V > {
223
+ unsafe fn borrow_table_mut ( & mut self ) -> & mut RawTable < K , V > ;
224
+ }
225
+
226
+
227
+ impl < ' t , K , V > Put < K , V > for & ' t mut RawTable < K , V > {
228
+ unsafe fn borrow_table_mut ( & mut self ) -> & mut RawTable < K , V > {
229
+ * self
223
230
}
224
231
}
225
232
233
+ impl < K , V , M > Put < K , V > for Bucket < K , V , M > where M : Put < K , V > {
234
+ unsafe fn borrow_table_mut ( & mut self ) -> & mut RawTable < K , V > {
235
+ self . table . borrow_table_mut ( )
236
+ }
237
+ }
226
238
227
- /// `Put` is implemented for types which provide access to a table and cannot be invalidated
228
- /// by filling a bucket. A similar implementation for `Take` is possible.
229
- pub trait Put { }
230
- impl < K , V > Put for RawTable < K , V > { }
231
- impl < ' t , K , V > Put for & ' t mut RawTable < K , V > { }
232
- impl < K , V , M : Put > Put for Bucket < K , V , M > { }
233
- impl < K , V , M : Put > Put for FullBucket < K , V , M > { }
239
+ impl < K , V , M > Put < K , V > for FullBucket < K , V , M > where M : Put < K , V > {
240
+ unsafe fn borrow_table_mut ( & mut self ) -> & mut RawTable < K , V > {
241
+ self . table . borrow_table_mut ( )
242
+ }
243
+ }
234
244
235
245
impl < K , V , M : Deref < Target =RawTable < K , V > > > Bucket < K , V , M > {
236
246
pub fn new ( table : M , hash : SafeHash ) -> Bucket < K , V , M > {
@@ -332,7 +342,7 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> EmptyBucket<K, V, M> {
332
342
}
333
343
}
334
344
335
- impl < K , V , M > EmptyBucket < K , V , M > where M : Deref < Target = RawTable < K , V > > + DerefMut + Put {
345
+ impl < K , V , M > EmptyBucket < K , V , M > where M : Put < K , V > {
336
346
/// Puts given key and value pair, along with the key's hash,
337
347
/// into this bucket in the hashtable. Note how `self` is 'moved' into
338
348
/// this function, because this slot will no longer be empty when
@@ -346,9 +356,9 @@ impl<K, V, M> EmptyBucket<K, V, M> where M: Deref<Target=RawTable<K, V>> + Deref
346
356
* self . raw . hash = hash. inspect ( ) ;
347
357
ptr:: write ( self . raw . key , key) ;
348
358
ptr:: write ( self . raw . val , value) ;
349
- }
350
359
351
- self . table . size += 1 ;
360
+ self . table . borrow_table_mut ( ) . size += 1 ;
361
+ }
352
362
353
363
FullBucket { raw : self . raw , idx : self . idx , table : self . table }
354
364
}
@@ -436,7 +446,7 @@ impl<'t, K, V> FullBucket<K, V, &'t mut RawTable<K, V>> {
436
446
}
437
447
}
438
448
439
- impl < K , V , M > FullBucket < K , V , M > where M : Deref < Target = RawTable < K , V > > + DerefMut {
449
+ impl < K , V , M > FullBucket < K , V , M > where M : Put < K , V > {
440
450
pub fn replace ( & mut self , h : SafeHash , k : K , v : V ) -> ( SafeHash , K , V ) {
441
451
unsafe {
442
452
let old_hash = ptr:: replace ( self . raw . hash as * mut SafeHash , h) ;
@@ -446,7 +456,9 @@ impl<K, V, M> FullBucket<K, V, M> where M: Deref<Target=RawTable<K, V>> + DerefM
446
456
( old_hash, old_key, old_val)
447
457
}
448
458
}
459
+ }
449
460
461
+ impl < K , V , M > FullBucket < K , V , M > where M : Deref < Target =RawTable < K , V > > + DerefMut {
450
462
/// Gets mutable references to the key and value at a given index.
451
463
pub fn read_mut ( & mut self ) -> ( & mut K , & mut V ) {
452
464
unsafe {
0 commit comments