diff --git a/crates/rbtree/src/raw_node.rs b/crates/rbtree/src/raw_node.rs index 86ba8b2..40b3a00 100644 --- a/crates/rbtree/src/raw_node.rs +++ b/crates/rbtree/src/raw_node.rs @@ -1,3 +1,4 @@ +use core::fmt::Debug; use core::marker::PhantomData; use core::mem; use core::ops::Not; @@ -657,6 +658,15 @@ pub struct RBTree { root: Option>, } +impl Debug for RBTree +where + N::Key: Debug, +{ + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_set().entries(self.iter()).finish() + } +} + impl RBTree { pub fn new() -> Self { Self { root: None } @@ -1153,7 +1163,9 @@ impl<'a, N: UnsafeNode + 'a> Iterator for TreeIter<'a, N> { fn next(&mut self) -> Option { self.range .next() - .map(|n| unsafe { n.node().unwrap().as_ref().key() }) + .as_ref() + .and_then(Handle::node) + .map(|n| unsafe { n.as_ref().key() }) } } @@ -1161,7 +1173,9 @@ impl<'a, N: UnsafeNode + 'a> DoubleEndedIterator for TreeIter<'a, N> { fn next_back(&mut self) -> Option { self.range .next_back() - .map(|n| unsafe { n.node().unwrap().as_ref().key() }) + .as_ref() + .and_then(Handle::node) + .map(|n| unsafe { n.as_ref().key() }) } }