1
0
Fork 0
forked from alemi/upub

fix(apb): id returns id of front for array node

This commit is contained in:
əlemi 2024-05-13 16:32:23 +02:00
parent d5e01cc655
commit 88a6048dc2
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -92,9 +92,10 @@ impl<T : super::Base> Node<T> {
/// returns id of object: url for link, id for object, None if empty or array /// returns id of object: url for link, id for object, None if empty or array
pub fn id(&self) -> Option<String> { pub fn id(&self) -> Option<String> {
match self { match self {
Node::Empty | Node::Array(_) => None, Node::Empty => None,
Node::Link(uri) => Some(uri.href().to_string()), Node::Link(uri) => Some(uri.href().to_string()),
Node::Object(obj) => obj.id().map(|x| x.to_string()), Node::Object(obj) => Some(obj.id()?.to_string()),
Node::Array(arr) => Some(arr.front()?.id()?.to_string()),
} }
} }
} }