@@ -2,11 +2,9 @@ use core::borrow::Borrow;
22use core:: fmt;
33use core:: mem;
44
5- use unreachable:: UncheckedOptionExt ;
6-
7- use iter:: { IntoIter , Iter , IterMut } ;
8- use sparse:: Sparse ;
9- use util:: { nybble_index, nybble_mismatch} ;
5+ use crate :: iter:: { IntoIter , Iter , IterMut } ;
6+ use crate :: sparse:: Sparse ;
7+ use crate :: util:: { nybble_index, nybble_mismatch} ;
108
119// A leaf in the trie.
1210#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -82,27 +80,26 @@ impl<K: Borrow<[u8]>, V> Branch<K, V> {
8280 pub fn entry_mut ( & mut self , index : u8 ) -> & mut Node < K , V > {
8381 let entry = self . entries . get_mut ( index) ;
8482 debug_assert ! ( entry. is_some( ) ) ;
85- unsafe { entry. unchecked_unwrap ( ) }
83+ unsafe { entry. unwrap_unchecked ( ) }
8684 }
8785
8886 // Get the child node corresponding to the given key.
8987 #[ inline]
9088 pub fn child ( & self , key : & [ u8 ] ) -> Option < & Node < K , V > > {
91- self . entries . get ( nybble_index ( self . choice , key. borrow ( ) ) )
89+ self . entries . get ( nybble_index ( self . choice , key) )
9290 }
9391
9492 // Mutable version of `Branch::child`.
9593 #[ inline]
9694 pub fn child_mut ( & mut self , key : & [ u8 ] ) -> Option < & mut Node < K , V > > {
97- self . entries
98- . get_mut ( nybble_index ( self . choice , key. borrow ( ) ) )
95+ self . entries . get_mut ( nybble_index ( self . choice , key) )
9996 }
10097
10198 // Immutably borrow the leaf for the given key, if it exists, mutually recursing through
10299 // `Node::get`.
103100 #[ inline]
104101 pub fn get ( & self , key : & [ u8 ] ) -> Option < & Leaf < K , V > > {
105- match self . child ( key. borrow ( ) ) {
102+ match self . child ( key) {
106103 Some ( child) => child. get ( key) ,
107104 None => None ,
108105 }
@@ -112,37 +109,34 @@ impl<K: Borrow<[u8]>, V> Branch<K, V> {
112109 // `Node::get_mut`.
113110 #[ inline]
114111 pub fn get_mut ( & mut self , key : & [ u8 ] ) -> Option < & mut Leaf < K , V > > {
115- self . child_mut ( key. borrow ( ) )
116- . and_then ( |node| node. get_mut ( key) )
112+ self . child_mut ( key) . and_then ( |node| node. get_mut ( key) )
117113 }
118114
119115 // Retrieve the node which contains the exemplar. This does not recurse and return the actual
120116 // exemplar - just the node which might be or contain it.
121117 #[ inline]
122118 pub fn exemplar ( & self , key : & [ u8 ] ) -> & Node < K , V > {
123- self . entries
124- . get_or_any ( nybble_index ( self . choice , key. borrow ( ) ) )
119+ self . entries . get_or_any ( nybble_index ( self . choice , key) )
125120 }
126121
127122 // As `Branch::exemplar` but for mutable borrows.
128123 #[ inline]
129124 pub fn exemplar_mut ( & mut self , key : & [ u8 ] ) -> & mut Node < K , V > {
130- self . entries
131- . get_or_any_mut ( nybble_index ( self . choice , key. borrow ( ) ) )
125+ self . entries . get_or_any_mut ( nybble_index ( self . choice , key) )
132126 }
133127
134128 // Immutably borrow the exemplar for the given key, mutually recursing through
135129 // `Node::get_exemplar`.
136130 #[ inline]
137131 pub fn get_exemplar ( & self , key : & [ u8 ] ) -> & Leaf < K , V > {
138- self . exemplar ( key. borrow ( ) ) . get_exemplar ( key)
132+ self . exemplar ( key) . get_exemplar ( key)
139133 }
140134
141135 // Mutably borrow the exemplar for the given key, mutually recursing through
142136 // `Node::get_exemplar_mut`.
143137 #[ inline]
144138 pub fn get_exemplar_mut ( & mut self , key : & [ u8 ] ) -> & mut Leaf < K , V > {
145- self . exemplar_mut ( key. borrow ( ) ) . get_exemplar_mut ( key)
139+ self . exemplar_mut ( key) . get_exemplar_mut ( key)
146140 }
147141
148142 // Convenience method for inserting a leaf into the branch's sparse array.
@@ -336,7 +330,7 @@ impl<K: Borrow<[u8]>, V> Node<K, V> {
336330 let child_opt = branch. child ( prefix) ;
337331
338332 // unsafe: child must exist in the trie - prefix'd nodes must exist.
339- let child = unsafe { child_opt. unchecked_unwrap ( ) } ;
333+ let child = unsafe { child_opt. unwrap_unchecked ( ) } ;
340334
341335 child. get_prefix_validated ( prefix)
342336 }
@@ -379,7 +373,7 @@ impl<K: Borrow<[u8]>, V> Node<K, V> {
379373
380374 // unsafe: child must exist as there must exist nodes with the given prefix in
381375 // the trie.
382- let child = unsafe { child_opt. unchecked_unwrap ( ) } ;
376+ let child = unsafe { child_opt. unwrap_unchecked ( ) } ;
383377
384378 child. get_prefix_validated_mut ( prefix)
385379 }
@@ -565,11 +559,11 @@ impl<K: Borrow<[u8]>, V> Node<K, V> {
565559 match * root {
566560 Some ( Node :: Leaf ( ..) )
567561 // unsafe: root has been match'd as some branch.
568- if unsafe { root. as_ref ( ) . unchecked_unwrap ( ) . unwrap_leaf_ref ( ) }
562+ if unsafe { root. as_ref ( ) . unwrap_unchecked ( ) . unwrap_leaf_ref ( ) }
569563 . key_slice ( ) == key => {
570564
571565 // unsafe: same rationale.
572- Some ( unsafe { root. take ( ) . unchecked_unwrap ( ) . unwrap_leaf ( ) } )
566+ Some ( unsafe { root. take ( ) . unwrap_unchecked ( ) . unwrap_leaf ( ) } )
573567 }
574568
575569 Some ( ref mut node @ Node :: Branch ( ..) ) => node. remove_validated ( key) ,
@@ -627,24 +621,24 @@ impl<K: Borrow<[u8]>, V> Node<K, V> {
627621 match * root {
628622 Some ( Node :: Leaf ( ..) )
629623 // unsafe: root has been matched as some leaf.
630- if unsafe { root. as_ref ( ) . unchecked_unwrap ( ) . unwrap_leaf_ref ( ) }
624+ if unsafe { root. as_ref ( ) . unwrap_unchecked ( ) . unwrap_leaf_ref ( ) }
631625 . key_slice ( )
632626 . starts_with ( prefix) => root. take ( ) ,
633627
634628 Some ( Node :: Branch ( ..) )
635629 // unsafe: root has been matched as some branch.
636- if unsafe { root. as_ref ( ) . unchecked_unwrap ( ) . unwrap_branch_ref ( ) }
630+ if unsafe { root. as_ref ( ) . unwrap_unchecked ( ) . unwrap_branch_ref ( ) }
637631 . get_exemplar ( prefix)
638632 . key_slice ( )
639633 . starts_with ( prefix) => {
640634
641635 // unsafe: same rationale.
642- if unsafe { root. as_ref ( ) . unchecked_unwrap ( ) . unwrap_branch_ref ( ) }
636+ if unsafe { root. as_ref ( ) . unwrap_unchecked ( ) . unwrap_branch_ref ( ) }
643637 . choice >= prefix. len ( ) * 2
644638 {
645639 root. take ( )
646640 } else {
647- unsafe { root. as_mut ( ) . unchecked_unwrap ( ) } . remove_prefix_validated ( prefix)
641+ unsafe { root. as_mut ( ) . unwrap_unchecked ( ) } . remove_prefix_validated ( prefix)
648642 }
649643 }
650644
0 commit comments