simplify validate_height

This commit is contained in:
AF 2023-08-01 20:25:14 +00:00
parent a6254d92b5
commit e6ff986e42

View File

@ -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> { impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> {
fn validate_height(&self) -> Result<(), HeightError> { fn validate_height(&self) -> Result<(), HeightError> {
if let Nullable::Null(_) = self.node { match (&self.node, self.height) {
if self.height != 0 { (Nullable::NotNull(_), 0) => Err(HeightError::NodeHeight),
Err(HeightError::LeafHeight(self.height))? (_, 0) => Ok(()),
(Nullable::Null(_), height) => Err(HeightError::LeafHeight(height)),
_ => Ok(()),
} }
} else if self.height == 0 {
Err(HeightError::NodeHeight)?
}
Ok(())
} }
} }