feat: Node::get() returns owned object

This commit is contained in:
əlemi 2024-03-26 00:49:42 +01:00
parent be75ac33d1
commit b0d8957f41
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -15,17 +15,14 @@ impl<T : super::Base> From<Option<T>> for Node<T> {
}
impl<T : super::Base> Node<T> {
pub fn get(&self) -> Option<&T> {
pub fn get(self) -> Option<T> {
match self {
Node::Empty | Node::Link(_) => None,
Node::Object(x) => Some(x),
Node::Array(v) => match v.iter().find_map(|x| match x {
Node::Object(x) => Some(x),
Node::Object(x) => Some(*x),
Node::Array(v) => v.into_iter().find_map(|x| match x {
Node::Object(x) => Some(*x),
_ => None,
}) {
Some(x) => Some(x),
None => None,
},
}),
}
}