Last active
August 29, 2015 13:57
-
-
Save Kimundi/9573000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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