@@ -21,6 +21,7 @@ use core::prelude::*;
21
21
use core:: { slice, mem, ptr, cmp, num, raw} ;
22
22
use core:: iter:: Zip ;
23
23
use core:: borrow:: BorrowFrom ;
24
+ use core:: ptr:: Unique ;
24
25
use alloc:: heap;
25
26
26
27
/// Represents the result of an Insertion: either the item fit, or the node had to split
@@ -51,11 +52,11 @@ pub struct Node<K, V> {
51
52
// These will never be null during normal usage of a `Node`. However, to avoid the need for a
52
53
// drop flag, `Node::drop` zeroes `keys`, signaling that the `Node` has already been cleaned
53
54
// up.
54
- keys : * mut K ,
55
- vals : * mut V ,
55
+ keys : Unique < K > ,
56
+ vals : Unique < V > ,
56
57
57
58
// In leaf nodes, this will be null, and no space will be allocated for edges.
58
- edges : * mut Node < K , V > ,
59
+ edges : Unique < Node < K , V > > ,
59
60
60
61
// At any given time, there will be `_len` keys, `_len` values, and (in an internal node)
61
62
// `_len + 1` edges. In a leaf node, there will never be any edges.
@@ -255,7 +256,7 @@ impl<T> Drop for RawItems<T> {
255
256
#[ unsafe_destructor]
256
257
impl < K , V > Drop for Node < K , V > {
257
258
fn drop ( & mut self ) {
258
- if self . keys . is_null ( ) {
259
+ if self . keys . 0 . is_null ( ) {
259
260
// We have already cleaned up this node.
260
261
return ;
261
262
}
@@ -269,7 +270,7 @@ impl<K, V> Drop for Node<K, V> {
269
270
self . destroy ( ) ;
270
271
}
271
272
272
- self . keys = ptr:: null_mut ( ) ;
273
+ self . keys . 0 = ptr:: null_mut ( ) ;
273
274
}
274
275
}
275
276
@@ -285,9 +286,9 @@ impl<K, V> Node<K, V> {
285
286
let ( vals_offset, edges_offset) = calculate_offsets_generic :: < K , V > ( capacity, false ) ;
286
287
287
288
Node {
288
- keys : buffer as * mut K ,
289
- vals : buffer. offset ( vals_offset as int ) as * mut V ,
290
- edges : buffer. offset ( edges_offset as int ) as * mut Node < K , V > ,
289
+ keys : Unique ( buffer as * mut K ) ,
290
+ vals : Unique ( buffer. offset ( vals_offset as int ) as * mut V ) ,
291
+ edges : Unique ( buffer. offset ( edges_offset as int ) as * mut Node < K , V > ) ,
291
292
_len : 0 ,
292
293
_capacity : capacity,
293
294
}
@@ -303,9 +304,9 @@ impl<K, V> Node<K, V> {
303
304
let ( vals_offset, _) = calculate_offsets_generic :: < K , V > ( capacity, true ) ;
304
305
305
306
Node {
306
- keys : buffer as * mut K ,
307
- vals : unsafe { buffer. offset ( vals_offset as int ) as * mut V } ,
308
- edges : ptr:: null_mut ( ) ,
307
+ keys : Unique ( buffer as * mut K ) .
308
+ vals: Unique ( unsafe { buffer. offset ( vals_offset as int ) as * mut V } ) ,
309
+ edges : Unique ( ptr:: null_mut :: < u8 > ( ) ) ,
309
310
_len : 0 ,
310
311
_capacity : capacity,
311
312
}
@@ -314,18 +315,18 @@ impl<K, V> Node<K, V> {
314
315
unsafe fn destroy ( & mut self ) {
315
316
let ( alignment, size) =
316
317
calculate_allocation_generic :: < K , V > ( self . capacity ( ) , self . is_leaf ( ) ) ;
317
- heap:: deallocate ( self . keys as * mut u8 , size, alignment) ;
318
+ heap:: deallocate ( self . keys . 0 as * mut u8 , size, alignment) ;
318
319
}
319
320
320
321
#[ inline]
321
322
pub fn as_slices < ' a > ( & ' a self ) -> ( & ' a [ K ] , & ' a [ V ] ) {
322
323
unsafe { (
323
324
mem:: transmute ( raw:: Slice {
324
- data : self . keys as * const K ,
325
+ data : self . keys . 0 as * const K ,
325
326
len : self . len ( )
326
327
} ) ,
327
328
mem:: transmute ( raw:: Slice {
328
- data : self . vals as * const V ,
329
+ data : self . vals . 0 as * const V ,
329
330
len : self . len ( )
330
331
} )
331
332
) }
@@ -344,7 +345,7 @@ impl<K, V> Node<K, V> {
344
345
} else {
345
346
unsafe {
346
347
mem:: transmute ( raw:: Slice {
347
- data : self . edges as * const Node < K , V > ,
348
+ data : self . edges . 0 as * const Node < K , V > ,
348
349
len : self . len ( ) + 1
349
350
} )
350
351
}
0 commit comments