diff --git a/src/lib.rs b/src/lib.rs index 1711575..952706b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,9 +177,9 @@ pub trait BinarySearchTree { /// or `None` if element does not exist. fn retrieve_as_mut(&mut self, value: &T) -> Option<&mut T>; - /// Returns the **height.** + /// Returns the **height** or `None` if tree is empty. /// - /// This is the number of edges between the root and it's furthest leaf node. + /// The height is the number of edges between the root and it's furthest leaf node. /// /// # Example /// @@ -393,10 +393,9 @@ impl BinarySearchTree for IterativeBST { } fn height(&self) -> Option { - match self.root { - None => None, - Some(_) => Some(Node::iterative_height(&self.root)), - } + self.root + .as_ref() + .map(|_| Node::iterative_height(&self.root)) } fn min(&self) -> Option<&T> {