tiny_json/walk.rs
1use std::ops::Deref;
2use crate::node::{Node, NodeChild, NodeType};
3
4/// 遍历节点
5pub fn walk(node: &Node, cb: fn(&Node)) {
6 match node.children.deref() {
7 NodeChild::KV { key, value } => {
8 cb(node);
9 walk(key, cb);
10 walk(value, cb);
11 }
12 NodeChild::List(list) => {
13 cb(node);
14 for n in list {
15 walk(n, cb);
16 }
17 }
18 NodeChild::Value(x) => {
19 cb(node);
20 }
21 NodeChild::Null => {
22 println!("Unexpected Error");
23 }
24 }
25}