use core::marker::PhantomData;
use core::mem;
-use core::nonzero::NonZero;
-use core::ptr::{self, Unique};
+use core::ptr::{self, Unique, NonNull};
use core::slice;
use boxed::Box;
}
}
- unsafe fn from_ptr(ptr: NonZero<*const LeafNode<K, V>>) -> Self {
- BoxedNode { ptr: Unique::new_unchecked(ptr.get() as *mut LeafNode<K, V>) }
+ unsafe fn from_ptr(ptr: NonNull<LeafNode<K, V>>) -> Self {
+ BoxedNode { ptr: Unique::from(ptr) }
}
- fn as_ptr(&self) -> NonZero<*const LeafNode<K, V>> {
- unsafe {
- NonZero::from(self.ptr.as_ref())
- }
+ fn as_ptr(&self) -> NonNull<LeafNode<K, V>> {
+ NonNull::from(self.ptr)
}
}
/// `NodeRef` could be pointing to either type of node.
pub struct NodeRef<BorrowType, K, V, Type> {
height: usize,
- node: NonZero<*const LeafNode<K, V>>,
+ node: NonNull<LeafNode<K, V>>,
// This is null unless the borrow type is `Mut`
root: *const Root<K, V>,
_marker: PhantomData<(BorrowType, Type)>
impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Internal> {
fn as_internal(&self) -> &InternalNode<K, V> {
unsafe {
- &*(self.node.get() as *const InternalNode<K, V>)
+ &*(self.node.as_ptr() as *mut InternalNode<K, V>)
}
}
}
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
fn as_internal_mut(&mut self) -> &mut InternalNode<K, V> {
unsafe {
- &mut *(self.node.get() as *mut InternalNode<K, V>)
+ &mut *(self.node.as_ptr() as *mut InternalNode<K, V>)
}
}
}
fn as_leaf(&self) -> &LeafNode<K, V> {
unsafe {
- &*self.node.get()
+ self.node.as_ref()
}
}
>,
Self
> {
- if let Some(non_zero) = NonZero::new(self.as_leaf().parent as *const LeafNode<K, V>) {
+ let parent_as_leaf = self.as_leaf().parent as *const LeafNode<K, V>;
+ if let Some(non_zero) = NonNull::new(parent_as_leaf as *mut _) {
Ok(Handle {
node: NodeRef {
height: self.height + 1,
fn as_leaf_mut(&mut self) -> &mut LeafNode<K, V> {
unsafe {
- &mut *(self.node.get() as *mut LeafNode<K, V>)
+ self.node.as_mut()
}
}
}
Heap.dealloc(
- right_node.node.get() as *mut u8,
+ right_node.node.as_ptr() as *mut u8,
Layout::new::<InternalNode<K, V>>(),
);
} else {
Heap.dealloc(
- right_node.node.get() as *mut u8,
+ right_node.node.as_ptr() as *mut u8,
Layout::new::<LeafNode<K, V>>(),
);
}