Skip to content

Commit 95972fe

Browse files
committed
Cleanup + cargo fmt
Cleaned up loop to skip 2nd access to `tree.node_mut`, and rust fmt the unit tests.
1 parent 72e73f4 commit 95972fe

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,12 @@ impl<'a, T: 'a> NodeMut<'a, T> {
846846
// Update parent for all siblings in the chain
847847
let mut child_id = new_child_ids.0;
848848
loop {
849-
unsafe { self.tree.node_mut(child_id).parent = Some(self.id); }
850-
if child_id == new_child_ids.1 { break; }
851-
child_id = unsafe { self.tree.node_mut(child_id).next_sibling.unwrap() };
849+
let child = unsafe { self.tree.node_mut(child_id) };
850+
child.parent = Some(self.id);
851+
child_id = match child.next_sibling {
852+
Some(id) => id,
853+
None => break,
854+
};
852855
}
853856

854857
if self.node().children.is_none() {
@@ -888,9 +891,12 @@ impl<'a, T: 'a> NodeMut<'a, T> {
888891
// Update parent for all siblings in the chain
889892
let mut child_id = new_child_ids.0;
890893
loop {
891-
unsafe { self.tree.node_mut(child_id).parent = Some(self.id); }
892-
if child_id == new_child_ids.1 { break; }
893-
child_id = unsafe { self.tree.node_mut(child_id).next_sibling.unwrap() };
894+
let child = unsafe { self.tree.node_mut(child_id) };
895+
child.parent = Some(self.id);
896+
child_id = match child.next_sibling {
897+
Some(id) => id,
898+
None => break,
899+
};
894900
}
895901

896902
if self.node().children.is_none() {

tests/node_mut.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ fn reparent_from_id_append_multiple_siblings() {
512512
.reparent_from_id_append(c_id);
513513

514514
let b = tree.get(b_id).unwrap();
515-
let x = b.first_child().unwrap(); // original child of b
516-
let d = x.next_sibling().unwrap(); // first reparented child
517-
let e = d.next_sibling().unwrap(); // middle reparented child
518-
let f = e.next_sibling().unwrap(); // last reparented child
515+
let x = b.first_child().unwrap(); // original child of b
516+
let d = x.next_sibling().unwrap(); // first reparented child
517+
let e = d.next_sibling().unwrap(); // middle reparented child
518+
let f = e.next_sibling().unwrap(); // last reparented child
519519

520520
// All children should now have 'b' as their parent
521521
assert_eq!(Some(b), x.parent());
@@ -544,7 +544,7 @@ fn reparent_from_id_prepend_multiple_siblings() {
544544
.reparent_from_id_prepend(c_id);
545545

546546
let b = tree.get(b_id).unwrap();
547-
let d = b.first_child().unwrap(); // first reparented child
547+
let d = b.first_child().unwrap(); // first reparented child
548548
let e = d.next_sibling().unwrap(); // middle reparented child
549549
let f = e.next_sibling().unwrap(); // last reparented child
550550
let x = f.next_sibling().unwrap(); // original child of b

0 commit comments

Comments
 (0)