Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a public get_tree() method and have print_tree use it #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 17 additions & 6 deletions src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down