Allègement du graphe
This commit is contained in:
parent
8f2b55fede
commit
115f907113
10
src/main.rs
10
src/main.rs
@ -51,17 +51,19 @@ fn main() {
|
||||
}
|
||||
|
||||
fn recurse_export(node: &TreeNode, parent_name: &str, out: &mut String) {
|
||||
if !parent_name.is_empty() && node.r#type.can_have_children() {
|
||||
writeln!(out, "\"{}\" -> \"{}\";", parent_name, node.print_name()).unwrap();
|
||||
if !parent_name.is_empty() && matches!(node.r#type, NodeType::Object { .. }) {
|
||||
writeln!(out, "\"{}\" -> \"{}\";", parent_name, node.name).unwrap();
|
||||
}
|
||||
|
||||
match &node.r#type {
|
||||
NodeType::Array { item } => {
|
||||
recurse_export(item, &node.print_name(), out);
|
||||
let mut item = item.clone();
|
||||
item.name.push_str(" []");
|
||||
recurse_export(&item, parent_name, out);
|
||||
}
|
||||
NodeType::Object { children, .. } => {
|
||||
for child in children {
|
||||
recurse_export(child, &node.print_name(), out);
|
||||
recurse_export(child, &node.name, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user