From 115f907113ea5689bda4b934d1eca16391828b36 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Fri, 3 Feb 2023 09:06:05 +0100 Subject: [PATCH] =?UTF-8?q?All=C3=A8gement=20du=20graphe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9dd7205..b118590 100644 --- a/src/main.rs +++ b/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); } }