1
0
Fork 0
forked from alemi/upub

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
This commit is contained in:
əlemi 2024-04-23 23:27:01 +02:00
parent deb5fe5744
commit d50a762f63
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -37,7 +37,7 @@ impl<T : super::Base> Node<T> {
match self { match self {
Node::Empty | Node::Link(_) => None, Node::Empty | Node::Link(_) => None,
Node::Object(x) => Some(x), Node::Object(x) => Some(x),
Node::Array(v) => v.get(0), Node::Array(v) => v.front(),
} }
} }
@ -51,7 +51,7 @@ impl<T : super::Base> Node<T> {
} }
/// true only if Node is empty /// true only if Node is empty
pub fn is_empty(&self) -> bool { pub fn is_nothing(&self) -> bool {
matches!(self, Node::Empty) matches!(self, Node::Empty)
} }
@ -70,6 +70,12 @@ impl<T : super::Base> Node<T> {
matches!(self, Node::Array(_)) 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) /// returns number of contained items (links count as items for len)
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
match self { match self {