From 9663e952107606bda50297f2e55997228c54000e Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 15 Aug 2025 23:25:05 +0200 Subject: [PATCH] refactor(tree): simplify NodeRef type by removing redundant parameters - Removed the `Type` parameter from `NodeRef` and related structs and methods --- src/tree.rs | 353 ++++++++++++++-------------------------------------- 1 file changed, 96 insertions(+), 257 deletions(-) diff --git a/src/tree.rs b/src/tree.rs index 0c3c78f..4ab267c 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -13,13 +13,7 @@ // tree.find('i') -> None use alloc::boxed::Box; -use core::{ - borrow::Borrow, - cmp::Ordering, - marker::PhantomData, - mem::{ManuallyDrop, MaybeUninit}, - ptr::NonNull, -}; +use core::{marker::PhantomData, mem::MaybeUninit, ptr::NonNull}; mod marker { use core::marker::PhantomData; @@ -80,9 +74,9 @@ struct LeafNode { type BoxedNode = NonNull>; #[derive(Debug)] -struct NodeRef { +struct NodeRef { node: NonNull>, - _marker: PhantomData<(BorrowType, Type)>, + _marker: PhantomData, } #[derive(Debug)] @@ -92,23 +86,23 @@ struct Handle { _marker: PhantomData, } -impl<'a, K: 'a, V: 'a, Type> Copy for NodeRef, K, V, Type> {} -impl<'a, K: 'a, V: 'a, Type> Clone for NodeRef, K, V, Type> { +impl<'a, K: 'a, V: 'a> Copy for NodeRef, K, V> {} +impl<'a, K: 'a, V: 'a> Clone for NodeRef, K, V> { fn clone(&self) -> Self { *self } } -unsafe impl Sync for NodeRef {} +unsafe impl Sync for NodeRef {} -unsafe impl Send for NodeRef, K, V, Type> {} -unsafe impl Send for NodeRef, K, V, Type> {} -unsafe impl Send for NodeRef, K, V, Type> {} -unsafe impl Send for NodeRef {} -unsafe impl Send for NodeRef {} +unsafe impl Send for NodeRef, K, V> {} +unsafe impl Send for NodeRef, K, V> {} +unsafe impl Send for NodeRef, K, V> {} +unsafe impl Send for NodeRef {} +unsafe impl Send for NodeRef {} -impl Handle, marker::Edge> { - unsafe fn new_edge(node: NodeRef, idx: usize) -> Self { +impl Handle, marker::Edge> { + unsafe fn new_edge(node: NodeRef, idx: usize) -> Self { Self { node, idx, @@ -116,8 +110,8 @@ impl Handle, marker::Edg } } } -impl Handle, marker::Value> { - unsafe fn new_value(node: NodeRef) -> Self { +impl Handle, marker::Value> { + unsafe fn new_value(node: NodeRef) -> Self { Self { node, idx: 0, @@ -149,8 +143,8 @@ impl LeafNode { } } -impl NodeRef { - fn new_leaf() -> Self { +impl NodeRef { + fn new() -> Self { let node = LeafNode::new(); NodeRef { node: Box::into_non_null(node), @@ -159,21 +153,7 @@ impl NodeRef { } } -impl NodeRef { - /// Unpack a node reference that was packed as `NodeRef::parent`. - fn new_internal(node: BoxedNode) -> Self { - let node = NodeRef { - node, - _marker: PhantomData, - }; - - // debug_assert!(!node.is_leaf()); - - node - } -} - -impl NodeRef { +impl NodeRef { /// Finds the parent of the current node. Returns `Ok(handle)` if the current /// node actually has a parent, where `handle` points to the edge of the parent /// that points to the current node. Returns `Err(self)` if the current node has @@ -183,9 +163,7 @@ impl NodeRef /// /// `edge.descend().ascend().unwrap()` and `node.ascend().unwrap().descend()` should /// both, upon success, do nothing. - pub(super) fn ascend( - self, - ) -> Result, marker::Edge>, Self> { + pub(super) fn ascend(self) -> Result, marker::Edge>, Self> { const { assert!(BorrowType::TRAVERSAL_PERMIT); } @@ -206,27 +184,14 @@ impl NodeRef } } -impl NodeRef { - pub(super) fn first_edge(self) -> Handle { - unsafe { Handle::new_edge(self, 0) } - } - - pub(super) fn last_edge(self) -> Handle { - let len = self.len(); - unsafe { Handle::new_edge(self, len) } - } -} - -impl - Handle, marker::Edge> -{ +impl Handle, marker::Edge> { /// Finds the node pointed to by this edge. /// /// The method name assumes you picture trees with the root node on top. /// /// `edge.descend().ascend().unwrap()` and `node.ascend().unwrap().descend()` should /// both, upon success, do nothing. - pub(super) fn descend(self) -> NodeRef { + pub(super) fn descend(self) -> NodeRef { const { assert!(BorrowType::TRAVERSAL_PERMIT); } @@ -249,7 +214,7 @@ impl } } -impl<'a, K, V, NodeType, HandleType> Handle, K, V, NodeType>, HandleType> { +impl<'a, K, V, HandleType> Handle, K, V>, HandleType> { /// Temporarily takes out another mutable handle on the same location. Beware, as /// this method is very dangerous, doubly so since it might not immediately appear /// dangerous. @@ -257,7 +222,7 @@ impl<'a, K, V, NodeType, HandleType> Handle, K, V, NodeT /// For details, see `NodeRef::reborrow_mut`. pub(super) unsafe fn reborrow_mut( &mut self, - ) -> Handle, K, V, NodeType>, HandleType> { + ) -> Handle, K, V>, HandleType> { // We can't use Handle::new_kv or Handle::new_edge because we don't know our type Handle { node: unsafe { self.node.reborrow_mut() }, @@ -269,9 +234,7 @@ impl<'a, K, V, NodeType, HandleType> Handle, K, V, NodeT /// Returns a dormant copy of this handle which can be reawakened later. /// /// See `DormantMutRef` for more details. - pub(super) fn dormant( - &self, - ) -> Handle, HandleType> { + pub(super) fn dormant(&self) -> Handle, HandleType> { Handle { node: self.node.dormant(), idx: self.idx, @@ -280,7 +243,7 @@ impl<'a, K, V, NodeType, HandleType> Handle, K, V, NodeT } } -impl<'a, K, V, NodeType> NodeRef, K, V, NodeType> { +impl<'a, K, V> NodeRef, K, V> { pub(super) fn len_mut(&mut self) -> &mut u16 { // SAFETY: we have exclusive access to the entire node. unsafe { &mut (*Self::as_leaf_ptr(self)).len } @@ -291,11 +254,11 @@ impl<'a, K, V, NodeType> NodeRef, K, V, NodeType> { } } -impl NodeRef { +impl NodeRef { /// Mutably borrows the owned root node. Unlike `reborrow_mut`, this is safe /// because the return value cannot be used to destroy the root, and there /// cannot be other references to the tree. - pub(super) fn borrow_mut(&mut self) -> NodeRef, K, V, Type> { + pub(super) fn borrow_mut(&mut self) -> NodeRef, K, V> { NodeRef { node: self.node, _marker: PhantomData, @@ -303,7 +266,7 @@ impl NodeRef { } /// Slightly mutably borrows the owned root node. - pub(super) fn borrow_valmut(&mut self) -> NodeRef, K, V, Type> { + pub(super) fn borrow_valmut(&mut self) -> NodeRef, K, V> { NodeRef { node: self.node, _marker: PhantomData, @@ -312,7 +275,7 @@ impl NodeRef { /// Irreversibly transitions to a reference that permits traversal and offers /// destructive methods and little else. - pub(super) fn into_dying(self) -> NodeRef { + pub(super) fn into_dying(self) -> NodeRef { NodeRef { node: self.node, _marker: PhantomData, @@ -320,7 +283,7 @@ impl NodeRef { } } -impl<'a, K, V, Type> NodeRef, K, V, Type> { +impl<'a, K, V> NodeRef, K, V> { /// Temporarily takes out another mutable reference to the same node. Beware, as /// this method is very dangerous, doubly so since it might not immediately appear /// dangerous. @@ -331,7 +294,7 @@ impl<'a, K, V, Type> NodeRef, K, V, Type> { // FIXME(@gereeter) consider adding yet another type parameter to `NodeRef` // that restricts the use of navigation methods on reborrowed pointers, // preventing this unsafety. - unsafe fn reborrow_mut(&mut self) -> NodeRef, K, V, Type> { + unsafe fn reborrow_mut(&mut self) -> NodeRef, K, V> { NodeRef { node: self.node, _marker: PhantomData, @@ -354,7 +317,7 @@ impl<'a, K, V, Type> NodeRef, K, V, Type> { /// Returns a dormant copy of this node with its lifetime erased which can /// be reawakened later. - pub(super) fn dormant(&self) -> NodeRef { + pub(super) fn dormant(&self) -> NodeRef { NodeRef { node: self.node, _marker: PhantomData, @@ -362,7 +325,7 @@ impl<'a, K, V, Type> NodeRef, K, V, Type> { } } -impl<'a, K: 'a, V: 'a, BorrowType> NodeRef { +impl<'a, K: 'a, V: 'a, BorrowType> NodeRef { /// Borrows shared access to an element of the key storage area. /// /// # Safety @@ -400,7 +363,7 @@ impl<'a, K: 'a, V: 'a, BorrowType> NodeRef { } } -impl<'a, K: 'a, V: 'a, NodeType> NodeRef, K, V, NodeType> { +impl<'a, K: 'a, V: 'a> NodeRef, K, V> { /// Borrows exclusive access to an element of the key storage area. /// /// # Safety @@ -438,14 +401,14 @@ impl<'a, K: 'a, V: 'a, NodeType> NodeRef, K, V, NodeType> { } } -impl NodeRef { +impl NodeRef { /// Revert to the unique borrow initially captured. /// /// # Safety /// /// The reborrow must have ended, i.e., the reference returned by `new` and /// all pointers and references derived from it, must not be used anymore. - pub(super) unsafe fn awaken<'a>(self) -> NodeRef, K, V, Type> { + pub(super) unsafe fn awaken<'a>(self) -> NodeRef, K, V> { NodeRef { node: self.node, _marker: PhantomData, @@ -453,16 +416,14 @@ impl NodeRef { } } -impl Handle, HandleType> { +impl Handle, HandleType> { /// Revert to the unique borrow initially captured. /// /// # Safety /// /// The reborrow must have ended, i.e., the reference returned by `new` and /// all pointers and references derived from it, must not be used anymore. - pub(super) unsafe fn awaken<'a>( - self, - ) -> Handle, K, V, NodeType>, HandleType> { + pub(super) unsafe fn awaken<'a>(self) -> Handle, K, V>, HandleType> { Handle { node: unsafe { self.node.awaken() }, idx: self.idx, @@ -471,7 +432,7 @@ impl Handle NodeRef { +impl NodeRef { /// Finds the length of the node. This is the number of keys or values. /// The number of edges is `len() + 1`. /// Note that, despite being safe, calling this function can have the side effect @@ -487,13 +448,13 @@ impl NodeRef { } } -impl NodeRef { +impl NodeRef { pub(super) fn is_leaf(&self) -> bool { unsafe { (*Self::as_leaf_ptr(self)).len == 0 } } /// Temporarily takes out another, immutable reference to the same node. - pub(super) fn reborrow(&self) -> NodeRef, K, V, Type> { + pub(super) fn reborrow(&self) -> NodeRef, K, V> { NodeRef { node: self.node, _marker: PhantomData, @@ -521,7 +482,7 @@ impl NodeRef { } } -impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::Internal> { +impl<'a, K: 'a, V: 'a> NodeRef, K, V> { /// Borrows a view into the keys stored in the node. pub(super) fn keys(&self) -> &[K] { unsafe { self.key_area(..self.len()).assume_init_ref() } @@ -532,13 +493,9 @@ impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::Internal> { } } -impl - Handle, HandleType> -{ +impl Handle, HandleType> { /// Temporarily takes out another immutable handle on the same location. - pub(super) fn reborrow( - &self, - ) -> Handle, K, V, NodeType>, HandleType> { + pub(super) fn reborrow(&self) -> Handle, K, V>, HandleType> { // We can't use Handle::new_kv or Handle::new_edge because we don't know our type Handle { node: self.node.reborrow(), @@ -548,7 +505,7 @@ impl } } -impl<'a, K: 'a, V: 'a, Type> NodeRef, K, V, Type> { +impl<'a, K: 'a, V: 'a> NodeRef, K, V> { /// Exposes the leaf portion of any leaf or internal node in an immutable tree. fn into_leaf(self) -> &'a LeafNode { let ptr = Self::as_leaf_ptr(&self); @@ -557,7 +514,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef, K, V, Type> { } } -impl<'a, K: 'a, V: 'a, NodeType> Handle, K, V, NodeType>, marker::Value> { +impl<'a, K: 'a, V: 'a> Handle, K, V>, marker::Value> { pub(super) unsafe fn into_value(self) -> &'a V { let leaf = self.node.into_leaf(); let v = leaf.value.as_ref().unwrap(); @@ -565,7 +522,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle, K, V, NodeTyp } } -impl<'a, K: 'a, V: 'a, NodeType> Handle, K, V, NodeType>, marker::Value> { +impl<'a, K: 'a, V: 'a> Handle, K, V>, marker::Value> { pub(super) unsafe fn value_mut(&mut self) -> &mut V { let leaf = self.node.as_leaf_mut(); let v = leaf.value.as_mut().unwrap(); @@ -578,44 +535,13 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle, K, V, NodeType> } } -impl Handle, marker::Edge> { - pub(super) fn forget_node_type( - self, - ) -> Handle, marker::Edge> { - unsafe { Handle::new_edge(self.node.forget_type(), self.idx) } - } +pub(super) enum ForceResult { + Leaf(Node), + Internal(Node), } -impl Handle, marker::Edge> { - pub(super) fn forget_node_type( - self, - ) -> Handle, marker::Edge> { - unsafe { Handle::new_edge(self.node.forget_type(), self.idx) } - } -} - -impl Handle, marker::Value> { - pub(super) fn forget_node_type( - self, - ) -> Handle, marker::Value> { - unsafe { Handle::new_value(self.node.forget_type()) } - } -} - -pub(super) enum ForceResult { - Leaf(Leaf), - Internal(Internal), -} - -impl - Handle, HandleType> -{ - fn force( - self, - ) -> ForceResult< - Handle, HandleType>, - Handle, HandleType>, - > { +impl Handle, HandleType> { + fn force(self) -> ForceResult, HandleType>> { match self.node.force() { ForceResult::Leaf(leaf) => ForceResult::Leaf(Handle { node: leaf, @@ -631,57 +557,17 @@ impl } } -impl NodeRef { - fn force( - self, - ) -> ForceResult< - NodeRef, - NodeRef, - > { +impl NodeRef { + fn force(self) -> ForceResult> { if self.is_leaf() { - ForceResult::Leaf(NodeRef { - node: self.node, - _marker: PhantomData, - }) + ForceResult::Leaf(self) } else { - ForceResult::Internal(NodeRef { - node: self.node, - _marker: PhantomData, - }) + ForceResult::Internal(self) } } } -impl NodeRef { - /// Removes any static information asserting that this node is a `Leaf` node. - pub(super) fn forget_type(self) -> NodeRef { - NodeRef { - node: self.node, - _marker: PhantomData, - } - } -} - -impl NodeRef { - /// Removes any static information asserting that this node is an `Internal` node. - pub(super) fn forget_type(self) -> NodeRef { - NodeRef { - node: self.node, - _marker: PhantomData, - } - } -} - -impl NodeRef { - pub(super) fn as_leaf_or_internal(self) -> NodeRef { - NodeRef { - node: self.node, - _marker: PhantomData, - } - } -} - -impl<'a, K, V, Type> NodeRef, K, V, Type> { +impl<'a, K, V> NodeRef, K, V> { pub(super) fn grow_node(&mut self) { // grow the node let Some(new_capacity) = self.capacity_mut().checked_mul(2) else { @@ -722,12 +608,12 @@ impl<'a, K, V, Type> NodeRef, K, V, Type> { } } -impl NodeRef { - pub(super) fn reparent<'a, NodeType>( +impl NodeRef { + pub(super) fn reparent<'a>( mut self, - mut parent: Handle, K, V, NodeType>, marker::Edge>, + mut parent: Handle, K, V>, marker::Edge>, key: K, - ) -> NodeRef, K, V, Type> + ) -> NodeRef, K, V> where K: 'a, V: 'a, @@ -759,42 +645,21 @@ impl NodeRef { } } -impl Handle, marker::Edge> { +impl Handle, marker::Edge> { /// Converts this edge handle into a value handle. - pub(super) fn into_value( - self, - ) -> Handle, marker::Value> { + /// IMPORTANT: this handle points to the value of the node, not the edge. + pub(super) fn into_value(self) -> Handle, marker::Value> { unsafe { Handle::new_value(self.node) } } } -impl<'a, K, V> NodeRef, K, V, marker::LeafOrInternal> { - /// Unsafely asserts to the compiler the static information that this node is a `Leaf`. - pub(super) unsafe fn cast_to_leaf_unchecked( - self, - ) -> NodeRef, K, V, marker::Leaf> { - NodeRef { - node: self.node, - _marker: PhantomData, - } - } - - /// Unsafely asserts to the compiler the static information that this node is an `Internal`. - unsafe fn cast_to_internal_unchecked(self) -> NodeRef, K, V, marker::Internal> { - NodeRef { - node: self.node, - _marker: PhantomData, - } - } -} - -impl<'a, K: 'a, V: 'a, Type> Handle, K, V, Type>, marker::Edge> { +impl<'a, K: 'a, V: 'a> Handle, K, V>, marker::Edge> { /// Inserts a key-value pair into pub(super) unsafe fn insert_recursing( mut self, mut key_seq: Q, val: V, - ) -> Handle, K, V, marker::LeafOrInternal>, marker::Value> + ) -> Handle, K, V>, marker::Value> where Q: Iterator, K: Ord, @@ -803,11 +668,11 @@ impl<'a, K: 'a, V: 'a, Type> Handle, K, V, Type>, marker // key has run out: insert value here. self.node.as_leaf_mut().value = Some(val); // TODO: handle occupied values. - return unsafe { Handle::new_value(self.node.as_leaf_or_internal()) }; + return unsafe { Handle::new_value(self.node) }; }; let last = unsafe { - let child = NodeRef::new_leaf().reparent(self, key); + let child = NodeRef::new().reparent(self, key); Handle::new_edge(child, 0) .insert_recursing(key_seq, val) @@ -825,16 +690,13 @@ mod search { use core::borrow::Borrow; use core::cmp::Ordering; - pub(super) enum SearchResult { + pub(super) enum SearchResult { /// The node which contains the value for the key. - Found(Handle, marker::Value>), + Found(Handle, marker::Value>), /// The key was found, and the search should continue at the given edge. - GoDown(Handle, marker::Edge>), + GoDown(Handle, marker::Edge>), /// The key was not found, and should be inserted at the given position. - Insert( - K, - Handle, marker::Edge>, - ), + Insert(K, Handle, marker::Edge>), } pub(super) enum IndexResult { @@ -842,11 +704,8 @@ mod search { Insert(usize), } - impl NodeRef { - pub(super) fn search_tree( - mut self, - mut key: Q, - ) -> SearchResult + impl NodeRef { + pub(super) fn search_tree(mut self, mut key: Q) -> SearchResult where Q: Iterator, K: Ord, @@ -864,11 +723,8 @@ mod search { } } - impl NodeRef { - fn search_node( - self, - mut key: Q, - ) -> SearchResult + impl NodeRef { + fn search_node(self, mut key: Q) -> SearchResult where Q: Iterator, K: Ord, @@ -878,23 +734,21 @@ mod search { let Some(key) = key.next() else { // key has run out, a value is either occupying this // node, or belongs here. - return SearchResult::Found(unsafe { - Handle::new_value(self.as_leaf_or_internal()) - }); + return SearchResult::Found(unsafe { Handle::new_value(self) }); }; match self.force() { // self is a leaf node and doesn't contain any keys: // a new leaf node should be inserted at this point. ForceResult::Leaf(leaf) => { - SearchResult::Insert(key, unsafe { Handle::new_edge(leaf.forget_type(), 0) }) + SearchResult::Insert(key, unsafe { Handle::new_edge(leaf, 0) }) } ForceResult::Internal(internal) => { // search through the keys of the internal node match unsafe { internal.find_key_index(&key, 0) } { IndexResult::Insert(idx) => Insert(key, unsafe { // the key wasn't present, but should be inserted at `idx`. - Handle::new_edge(internal.forget_type(), idx) + Handle::new_edge(internal, idx) }), IndexResult::Edge(idx) => { // the key was found, continue searching down the edge @@ -906,7 +760,7 @@ mod search { } } - impl NodeRef { + impl NodeRef { /// # Safety /// `start_index` must be a valid edge index for the node. unsafe fn find_key_index(&self, key: &Q, start_index: usize) -> IndexResult @@ -975,8 +829,8 @@ mod search { } } -enum HandleOrTree<'a, BorrowType, K, V, NodeType, HandleType> { - Handle(Handle, HandleType>), +enum HandleOrTree<'a, BorrowType, K, V, HandleType> { + Handle(Handle, HandleType>), Tree(borrow::DormantMutRef<'a, Tree>), } @@ -1035,14 +889,12 @@ mod entry { Q: Iterator, { pub(super) key: Q, - pub(super) handle: - super::HandleOrTree<'a, marker::Mut<'a>, K, V, marker::LeafOrInternal, marker::Edge>, + pub(super) handle: super::HandleOrTree<'a, marker::Mut<'a>, K, V, marker::Edge>, pub(super) _marker: PhantomData<&'a mut (K, V)>, } pub struct OccupiedEntry<'a, K, V> { - pub(super) handle: - Handle, K, V, marker::LeafOrInternal>, marker::Value>, + pub(super) handle: Handle, K, V>, marker::Value>, pub(super) _marker: PhantomData<&'a mut (K, V)>, } @@ -1056,7 +908,7 @@ mod entry { pub fn into_subtree(self) -> super::subtree::Subtree> { super::subtree::Subtree { - root: self.handle.node.as_leaf_or_internal(), + root: self.handle.node, } } } @@ -1084,11 +936,7 @@ mod entry { HandleOrTree::Tree(mut tree) => { // SAFETY: there are no nodes in the tree yet let tree = unsafe { tree.reborrow() }; - let root = - tree.root - .insert(NodeRef::new_internal(alloc::boxed::Box::into_non_null( - LeafNode::new(), - ))); + let root = tree.root.insert(NodeRef::new()); unsafe { Handle::new_edge(root.borrow_mut(), 0).insert_recursing(self.key, value) @@ -1118,7 +966,7 @@ mod subtree { // BorrowType may be one of `Immut`, `Mut`. pub struct Subtree { - pub(super) root: NodeRef, + pub(super) root: NodeRef, } impl Subtree @@ -1145,9 +993,7 @@ mod subtree { { let root = self.root.reborrow(); match root.search_tree(&mut key_seq) { - search::SearchResult::Found(handle) => Some(Subtree { - root: handle.node.as_leaf_or_internal(), - }), + search::SearchResult::Found(handle) => Some(Subtree { root: handle.node }), _ => { // key not found None @@ -1183,9 +1029,7 @@ mod subtree { { let root = unsafe { self.root.reborrow_mut() }; match root.search_tree(&mut key_seq) { - search::SearchResult::Found(handle) => Some(Subtree { - root: handle.node.as_leaf_or_internal(), - }), + search::SearchResult::Found(handle) => Some(Subtree { root: handle.node }), _ => { // key not found None @@ -1209,7 +1053,7 @@ mod subtree { }), search::SearchResult::GoDown(handle) => Vacant(VacantEntry { key: key_seq.into(), - handle: HandleOrTree::Handle(handle.forget_node_type()), + handle: HandleOrTree::Handle(handle), _marker: PhantomData, }), search::SearchResult::Insert(key, handle) => Vacant(VacantEntry { @@ -1296,7 +1140,7 @@ mod borrow { } } -type Root = NodeRef; +type Root = NodeRef; struct Tree { root: Option>, @@ -1309,7 +1153,7 @@ impl<'a, K: core::fmt::Debug + 'a, V: core::fmt::Debug + 'a> core::fmt::Debug fo fn format_node_ref<'a, K: 'a, V: 'a>( f: &mut core::fmt::Formatter<'_>, - node: &NodeRef, K, V, marker::LeafOrInternal>, + node: &NodeRef, K, V>, ) -> core::fmt::Result where K: core::fmt::Debug, @@ -1351,7 +1195,7 @@ impl<'a, K: core::fmt::Debug + 'a, V: core::fmt::Debug + 'a> core::fmt::Debug fo Some(ref root) => { map.key(&"root").value_with(|f| { let internal = root.reborrow(); - format_node_ref(f, &internal.as_leaf_or_internal()) + format_node_ref(f, &internal) }); map.finish() @@ -1420,12 +1264,7 @@ where K: Ord, { fn as_subtree_mut<'a>(&'a mut self) -> Option>> { - let root = self - .root - .as_mut()? - .borrow_mut() - .dormant() - .as_leaf_or_internal(); + let root = self.root.as_mut()?.borrow_mut().dormant(); Some(subtree::Subtree { root: unsafe { root.awaken() }, @@ -1493,9 +1332,9 @@ mod tests { } } - let mut leaf = NodeRef::<_, (), Test, _>::new_leaf(); + let mut leaf = NodeRef::<_, (), Test>::new(); leaf.borrow_mut().as_leaf_mut().value = Some(Test("test")); - let mut root = NodeRef::new_leaf(); + let mut root = NodeRef::new(); let mut leaf = leaf.reparent(unsafe { Handle::new_edge(root.borrow_mut(), 0) }, ());