diff --git a/Cargo.toml b/Cargo.toml index b3df1006..fbe7be11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ travis-ci = { repository = "riker-rs/riker" } riker-macros = { path = "riker-macros", version = "0.1" } bytes = "0.4" chrono = "0.4" -config = "0.9" +config = "0.10.1" futures-preview = "0.3.0-alpha.16" log = { version = "0.4", features = ["std"] } rand = "0.4" diff --git a/src/system/system.rs b/src/system/system.rs index d00f019c..4bf278bc 100644 --- a/src/system/system.rs +++ b/src/system/system.rs @@ -239,24 +239,35 @@ impl ActorSystem { } pub fn print_tree(&self) { - fn print_node(sys: &ActorSystem, node: BasicActorRef, indent: &str) { + println!("{}", self.get_tree()); + } + + pub fn get_tree(&self) -> String { + let mut tree_str: String = String::new(); + fn get_node( + mut tree_str: &mut String, + sys: &ActorSystem, + node: BasicActorRef, + indent: &str, + ) -> String { if node.is_root() { - println!("{}", sys.name()); + tree_str.push_str(&mut format!("{}\n", sys.name())); for actor in node.children() { - print_node(sys, actor, ""); + get_node(&mut tree_str, sys, actor, ""); } } else { - println!("{}└─ {}", indent, node.name()); + tree_str.push_str(&mut format!("{}└─ {}\n", indent, node.name())); for actor in node.children() { - print_node(sys, actor, &(indent.to_string() + " ")); + get_node(tree_str, sys, actor, &(indent.to_string() + " ")); } } + tree_str.to_string() } let root = self.sys_actors.as_ref().unwrap().root.clone(); - print_node(self, root, ""); + get_node(&mut tree_str, self, root, "") } /// Returns the system root's actor reference