From e6ff986e420ccd1687c3ac18aac76bd456ed2e59 Mon Sep 17 00:00:00 2001
From: timofey <tim@ongoteam.yaconnect.com>
Date: Tue, 1 Aug 2023 20:25:14 +0000
Subject: [PATCH] simplify `validate_height`

---
 src/rstd/collections/tree.rs | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs
index 014d407..4c7e10b 100644
--- a/src/rstd/collections/tree.rs
+++ b/src/rstd/collections/tree.rs
@@ -70,14 +70,12 @@ pub struct Tree<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> {
 
 impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> {
     fn validate_height(&self) -> Result<(), HeightError> {
-        if let Nullable::Null(_) = self.node {
-            if self.height != 0 {
-                Err(HeightError::LeafHeight(self.height))?
-            }
-        } else if self.height == 0 {
-            Err(HeightError::NodeHeight)?
+        match (&self.node, self.height) {
+            (Nullable::NotNull(_), 0) => Err(HeightError::NodeHeight),
+            (_, 0) => Ok(()),
+            (Nullable::Null(_), height) => Err(HeightError::LeafHeight(height)),
+            _ => Ok(()),
         }
-        Ok(())
     }
 }