fix(apb): node.into::<Value>() -> node.into_inner()

This commit is contained in:
əlemi 2024-11-10 20:32:10 +01:00
parent 6793f0fdc9
commit 12073bfed4
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 15 additions and 1 deletions

View file

@ -311,7 +311,7 @@ pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node<
if node.is_nothing() { if node.is_nothing() {
set_maybe_value(obj, key, None) set_maybe_value(obj, key, None)
} else { } else {
set_maybe_value(obj, key, Some(node.into())) set_maybe_value(obj, key, Some(node.into_inner()))
} }
} }

View file

@ -133,6 +133,20 @@ impl<T : super::Base> Node<T> {
#[cfg(feature = "unstructured")] #[cfg(feature = "unstructured")]
impl Node<serde_json::Value> { impl Node<serde_json::Value> {
pub fn into_inner(self) -> serde_json::Value {
match self {
Self::Object(x) => *x,
Self::Link(l) => serde_json::Value::String(l.href().unwrap_or_default().to_string()),
Self::Empty => serde_json::Value::Null,
Self::Array(arr) => serde_json::Value::Array(
arr
.into_iter()
.map(|x| x.into_inner())
.collect()
),
}
}
pub fn link(uri: String) -> Self { pub fn link(uri: String) -> Self {
Node::Link(Box::new(uri)) Node::Link(Box::new(uri))
} }