Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Created March 14, 2014 18:34
Show Gist options
  • Save Kimundi/9553887 to your computer and use it in GitHub Desktop.
Save Kimundi/9553887 to your computer and use it in GitHub Desktop.
mod config {
pub enum Node<T> {
Directory(~str, ~[Node<T>]),
Entry(~str, ~T)
}
pub fn add_entry<T>(node: &Node<T>, entry: &Node<T>) -> ::std::option::Option<&Node<T>> {
match node {
Directory(name, list) => { ::std::vec::append_one(list, entry); Some(node) }
_ => { None }
}
}
}
fn main() {
let entry = config::Entry(~"test", ~0.0);
let dir = config::Directory(~"dir", ~[]);
let dir2 = config::add_entry(dir, entry);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment