Skip to content

Instantly share code, notes, and snippets.

@huonw
Forked from jroweboy/error
Last active August 29, 2015 13:57
Show Gist options
  • Save huonw/9721035 to your computer and use it in GitHub Desktop.
Save huonw/9721035 to your computer and use it in GitHub Desktop.
extern crate collections;
use collections::hashmap::HashMap;
struct Node {
data : ~str,
children : ~HashMap<~str, Node>,
}
impl Node {
fn new(data: ~str) -> Node {
Node{ data: data, children: ~HashMap::new() }
}
}
fn main() {
let v = ~[~"Hello", ~"Tree", ~"World"];
let mut main = Node::new(~"Testing");
let mut ptr = &mut main;
for a in v.move_iter() {
ptr = ptr.children.find_or_insert(a.clone(), Node::new(a));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment