}
}
- unsafe fn from_ptr(ptr: NonZero<*mut LeafNode<K, V>>) -> Self {
- BoxedNode { ptr: Unique::new(*ptr) }
+ unsafe fn from_ptr(ptr: NonZero<*const LeafNode<K, V>>) -> Self {
+ BoxedNode { ptr: Unique::new(*ptr as *mut LeafNode<K, V>) }
}
- fn as_ptr(&self) -> NonZero<*mut LeafNode<K, V>> {
+ fn as_ptr(&self) -> NonZero<*const LeafNode<K, V>> {
unsafe {
- NonZero::new(*self.ptr)
+ NonZero::new(*self.ptr as *const LeafNode<K, V>)
}
}
}
}
}
+// N.B. `NodeRef` is always covariant in `K` and `V`, even when the `BorrowType`
+// is `Mut`. This is technically wrong, but cannot result in any unsafety due to
+// internal use of `NodeRef` because we stay completely generic over `K` and `V`.
+// However, whenever a public type wraps `NodeRef`, make sure that it has the
+// correct variance.
/// A reference to a node.
///
/// This type has a number of paramaters that controls how it acts:
/// `NodeRef` could be pointing to either type of node.
pub struct NodeRef<BorrowType, K, V, Type> {
height: usize,
- node: NonZero<*mut LeafNode<K, V>>,
- root: *mut Root<K, V>,
+ node: NonZero<*const LeafNode<K, V>>,
+ root: *const Root<K, V>,
_marker: PhantomData<(BorrowType, Type)>
}
fn as_leaf_mut(&mut self) -> &mut LeafNode<K, V> {
unsafe {
- &mut **self.node
+ &mut *(*self.node as *mut LeafNode<K, V>)
}
}
impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
pub fn into_root_mut(self) -> &'a mut Root<K, V> {
unsafe {
- &mut *self.root
+ &mut *(self.root as *mut Root<K, V>)
}
}
}
self.node.as_leaf_mut().len -= 1;
+ left_node.as_leaf_mut().len += right_len as u16 + 1;
+
if self.node.height > 1 {
ptr::copy_nonoverlapping(
right_node.cast_unchecked().as_internal().edges.as_ptr(),
);
}
- left_node.as_leaf_mut().len += right_len as u16 + 1;
-
Handle::new_edge(self.node, self.idx)
}
}