43
43
44
44
use core:: marker:: PhantomData ;
45
45
use core:: mem;
46
- use core:: nonzero:: NonZero ;
47
- use core:: ptr:: { self , Unique } ;
46
+ use core:: ptr:: { self , Unique , NonNull } ;
48
47
use core:: slice;
49
48
50
49
use boxed:: Box ;
@@ -149,14 +148,12 @@ impl<K, V> BoxedNode<K, V> {
149
148
}
150
149
}
151
150
152
- unsafe fn from_ptr ( ptr : NonZero < * const LeafNode < K , V > > ) -> Self {
153
- BoxedNode { ptr : Unique :: new_unchecked ( ptr. get ( ) as * mut LeafNode < K , V > ) }
151
+ unsafe fn from_ptr ( ptr : NonNull < LeafNode < K , V > > ) -> Self {
152
+ BoxedNode { ptr : Unique :: from ( ptr) }
154
153
}
155
154
156
- fn as_ptr ( & self ) -> NonZero < * const LeafNode < K , V > > {
157
- unsafe {
158
- NonZero :: from ( self . ptr . as_ref ( ) )
159
- }
155
+ fn as_ptr ( & self ) -> NonNull < LeafNode < K , V > > {
156
+ NonNull :: from ( self . ptr )
160
157
}
161
158
}
162
159
@@ -276,7 +273,7 @@ impl<K, V> Root<K, V> {
276
273
/// `NodeRef` could be pointing to either type of node.
277
274
pub struct NodeRef < BorrowType , K , V , Type > {
278
275
height : usize ,
279
- node : NonZero < * const LeafNode < K , V > > ,
276
+ node : NonNull < LeafNode < K , V > > ,
280
277
// This is null unless the borrow type is `Mut`
281
278
root : * const Root < K , V > ,
282
279
_marker : PhantomData < ( BorrowType , Type ) >
@@ -302,15 +299,15 @@ unsafe impl<K: Send, V: Send, Type> Send
302
299
impl < BorrowType , K , V > NodeRef < BorrowType , K , V , marker:: Internal > {
303
300
fn as_internal ( & self ) -> & InternalNode < K , V > {
304
301
unsafe {
305
- & * ( self . node . get ( ) as * const InternalNode < K , V > )
302
+ & * ( self . node . as_ptr ( ) as * mut InternalNode < K , V > )
306
303
}
307
304
}
308
305
}
309
306
310
307
impl < ' a , K , V > NodeRef < marker:: Mut < ' a > , K , V , marker:: Internal > {
311
308
fn as_internal_mut ( & mut self ) -> & mut InternalNode < K , V > {
312
309
unsafe {
313
- & mut * ( self . node . get ( ) as * mut InternalNode < K , V > )
310
+ & mut * ( self . node . as_ptr ( ) as * mut InternalNode < K , V > )
314
311
}
315
312
}
316
313
}
@@ -352,7 +349,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
352
349
353
350
fn as_leaf ( & self ) -> & LeafNode < K , V > {
354
351
unsafe {
355
- & * self . node . get ( )
352
+ self . node . as_ref ( )
356
353
}
357
354
}
358
355
@@ -382,7 +379,8 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
382
379
> ,
383
380
Self
384
381
> {
385
- if let Some ( non_zero) = NonZero :: new ( self . as_leaf ( ) . parent as * const LeafNode < K , V > ) {
382
+ let parent_as_leaf = self . as_leaf ( ) . parent as * const LeafNode < K , V > ;
383
+ if let Some ( non_zero) = NonNull :: new ( parent_as_leaf as * mut _ ) {
386
384
Ok ( Handle {
387
385
node : NodeRef {
388
386
height : self . height + 1 ,
@@ -498,7 +496,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
498
496
499
497
fn as_leaf_mut ( & mut self ) -> & mut LeafNode < K , V > {
500
498
unsafe {
501
- & mut * ( self . node . get ( ) as * mut LeafNode < K , V > )
499
+ self . node . as_mut ( )
502
500
}
503
501
}
504
502
@@ -1241,12 +1239,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
1241
1239
}
1242
1240
1243
1241
Heap . dealloc (
1244
- right_node. node . get ( ) as * mut u8 ,
1242
+ right_node. node . as_ptr ( ) as * mut u8 ,
1245
1243
Layout :: new :: < InternalNode < K , V > > ( ) ,
1246
1244
) ;
1247
1245
} else {
1248
1246
Heap . dealloc (
1249
- right_node. node . get ( ) as * mut u8 ,
1247
+ right_node. node . as_ptr ( ) as * mut u8 ,
1250
1248
Layout :: new :: < LeafNode < K , V > > ( ) ,
1251
1249
) ;
1252
1250
}
0 commit comments