Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Last active August 29, 2015 13:57
Show Gist options
  • Save Kimundi/9573000 to your computer and use it in GitHub Desktop.
Save Kimundi/9573000 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<'a, T>(node: &'a mut Node<T>, entry: Node<T>) -> Option<&'a mut Node<T>> {
if match node {
&Directory(_, ref mut list) => { list.push(entry); true }
_ => false
} { Some(node) } else { None }
}
}
fn main() {
let entry = ~config::Entry(~"test", ~0.0);
let mut 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