diff --git a/apb/src/node.rs b/apb/src/node.rs index 84fe410..d5e2433 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -11,6 +11,26 @@ pub enum Node { Empty, } +impl std::fmt::Debug for Node { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if f.alternate() { + match self { + Self::Array(x) => write!(f, "Node(array: {x:#?})"), + Self::Link(x) => write!(f, "Node(link: {})", x.href().unwrap_or_default()), + Self::Object(x) => write!(f, "Node(object: {x:#?})"), + Self::Empty => write!(f, "Node(empty)"), + } + } else { + match self { + Self::Array(x) => write!(f, "Node(array: {x:?})"), + Self::Link(x) => write!(f, "Node(link: {})", x.href().unwrap_or_default()), + Self::Object(x) => write!(f, "Node(object: {x:?})"), + Self::Empty => write!(f, "Node(empty)"), + } + } + } +} + // TODO convert in a from_residual (iirc?) so that in rust nightly we can do ? impl From> for Node { fn from(value: Option) -> Self { @@ -248,16 +268,3 @@ impl From for Node { } } } - -#[cfg(feature = "unstructured")] -impl From> for serde_json::Value { - fn from(value: Node) -> Self { - match value { - Node::Empty => serde_json::Value::Null, - Node::Link(l) => serde_json::Value::String(l.href().unwrap_or_default().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()), - } - } -}