simplify validate_height
This commit is contained in:
parent
a6254d92b5
commit
e6ff986e42
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user