fix(apb): simpler macros, added into value, fix links
before array of links were silently discarded because macros relied on into_iter().collect()... oops! technical debt, but should be ok now
This commit is contained in:
parent
dd16279003
commit
7e93bc6454
2 changed files with 19 additions and 42 deletions
|
@ -339,27 +339,10 @@ pub(crate) use setter;
|
|||
|
||||
#[cfg(feature = "unstructured")]
|
||||
pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node<serde_json::Value>) {
|
||||
match node {
|
||||
crate::Node::Object(x) => {
|
||||
set_maybe_value(
|
||||
obj, key, Some(*x),
|
||||
);
|
||||
},
|
||||
crate::Node::Link(l) => {
|
||||
set_maybe_value(
|
||||
obj, key, Some(serde_json::Value::String(l.href().to_string())),
|
||||
);
|
||||
},
|
||||
crate::Node::Array(_) => {
|
||||
set_maybe_value(
|
||||
obj, key, Some(serde_json::Value::Array(node.into_iter().collect())),
|
||||
);
|
||||
},
|
||||
crate::Node::Empty => {
|
||||
set_maybe_value(
|
||||
obj, key, None,
|
||||
);
|
||||
},
|
||||
if node.is_nothing() {
|
||||
set_maybe_value(obj, key, None)
|
||||
} else {
|
||||
set_maybe_value(obj, key, Some(node.into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,27 +369,9 @@ pub(crate) trait InsertValue {
|
|||
#[cfg(feature = "unstructured")]
|
||||
impl InsertValue for serde_json::Map<String, serde_json::Value> {
|
||||
fn insert_node(&mut self, k: &str, node: crate::Node<serde_json::Value>) {
|
||||
match node {
|
||||
crate::Node::Object(x) => {
|
||||
self.insert(
|
||||
k.to_string(),
|
||||
*x,
|
||||
);
|
||||
},
|
||||
crate::Node::Array(ref _arr) => {
|
||||
self.insert(
|
||||
k.to_string(),
|
||||
serde_json::Value::Array(node.into_iter().collect()),
|
||||
);
|
||||
},
|
||||
crate::Node::Link(l) => {
|
||||
self.insert(
|
||||
k.to_string(),
|
||||
serde_json::Value::String(l.href().to_string()),
|
||||
);
|
||||
},
|
||||
crate::Node::Empty => {},
|
||||
};
|
||||
if !node.is_nothing() {
|
||||
self.insert(k.to_string(), node.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_str(&mut self, k: &str, v: Option<&str>) {
|
||||
|
|
|
@ -222,3 +222,15 @@ impl From<serde_json::Value> for Node<serde_json::Value> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstructured")]
|
||||
impl From<Node<serde_json::Value>> for serde_json::Value {
|
||||
fn from(value: Node<serde_json::Value>) -> Self {
|
||||
match value {
|
||||
Node::Empty => serde_json::Value::Null,
|
||||
Node::Link(l) => serde_json::Value::String(l.href().to_string()), // TODO there could be more
|
||||
Node::Object(o) => *o,
|
||||
Node::Array(arr) =>
|
||||
serde_json::Value::Array(arr.into_iter().map(|x| x.into()).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue