From d50a762f63d830ec154f6a52a36cc78e98290f04 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 23 Apr 2024 23:27:01 +0200 Subject: [PATCH] fix(apb): is_empty === len()==0, new is_nothing basically is_empty on an empty Node::Vec is true, but is_nothing on an empty Node::Vec is false --- apb/src/node.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apb/src/node.rs b/apb/src/node.rs index fa1c7d70..b79bd79f 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -37,7 +37,7 @@ impl Node { match self { Node::Empty | Node::Link(_) => None, Node::Object(x) => Some(x), - Node::Array(v) => v.get(0), + Node::Array(v) => v.front(), } } @@ -51,7 +51,7 @@ impl Node { } /// true only if Node is empty - pub fn is_empty(&self) -> bool { + pub fn is_nothing(&self) -> bool { matches!(self, Node::Empty) } @@ -70,6 +70,12 @@ impl Node { matches!(self, Node::Array(_)) } + /// true only if Node is empty + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + /// returns number of contained items (links count as items for len) pub fn len(&self) -> usize { match self {