@@ -1159,6 +1159,12 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>
11591159 ( key, val)
11601160 }
11611161 }
1162+
1163+ /// Replace the key and value that the KV handle refers to.
1164+ pub fn replace_kv ( & mut self , k : K , v : V ) -> ( K , V ) {
1165+ let ( key, val) = self . kv_mut ( ) ;
1166+ ( mem:: replace ( key, k) , mem:: replace ( val, v) )
1167+ }
11621168}
11631169
11641170impl < ' a , K : ' a , V : ' a , NodeType > Handle < NodeRef < marker:: Mut < ' a > , K , V , NodeType > , marker:: KV > {
@@ -1432,8 +1438,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
14321438 unsafe {
14331439 let ( k, v, edge) = self . left_child . pop ( ) ;
14341440
1435- let k = mem:: replace ( self . parent . kv_mut ( ) . 0 , k) ;
1436- let v = mem:: replace ( self . parent . kv_mut ( ) . 1 , v) ;
1441+ let ( k, v) = self . parent . replace_kv ( k, v) ;
14371442
14381443 match self . right_child . reborrow_mut ( ) . force ( ) {
14391444 ForceResult :: Leaf ( mut leaf) => leaf. push_front ( k, v) ,
@@ -1455,8 +1460,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
14551460 unsafe {
14561461 let ( k, v, edge) = self . right_child . pop_front ( ) ;
14571462
1458- let k = mem:: replace ( self . parent . kv_mut ( ) . 0 , k) ;
1459- let v = mem:: replace ( self . parent . kv_mut ( ) . 1 , v) ;
1463+ let ( k, v) = self . parent . replace_kv ( k, v) ;
14601464
14611465 match self . left_child . reborrow_mut ( ) . force ( ) {
14621466 ForceResult :: Leaf ( mut leaf) => leaf. push ( k, v) ,
0 commit comments