From 12073bfed4a7a0167d82e8606f25e63659263859 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 10 Nov 2024 20:32:10 +0100 Subject: [PATCH] fix(apb): node.into::() -> node.into_inner() --- apb/src/macros.rs | 2 +- apb/src/node.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apb/src/macros.rs b/apb/src/macros.rs index 43faf38..a805721 100644 --- a/apb/src/macros.rs +++ b/apb/src/macros.rs @@ -311,7 +311,7 @@ pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node< if node.is_nothing() { set_maybe_value(obj, key, None) } else { - set_maybe_value(obj, key, Some(node.into())) + set_maybe_value(obj, key, Some(node.into_inner())) } } diff --git a/apb/src/node.rs b/apb/src/node.rs index 22aa12b..84fe410 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -133,6 +133,20 @@ impl Node { #[cfg(feature = "unstructured")] impl Node { + 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 { Node::Link(Box::new(uri)) }