Created
April 26, 2019 22:30
-
-
Save rust-play/c7d90e914d8449562e4e8cc9d3eca2ce to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
#[derive(Debug)] | |
struct Node<'a> { | |
id: &'a str, | |
children: Option<Vec<Node<'a>>>, | |
} | |
fn make_leaf<'a>(id: &'a str) -> Node<'a> { | |
Node { | |
id: id, | |
children: None | |
} | |
} | |
fn make_parent<'a>(id: &'a str, children: Vec<Node<'a>>) -> Node<'a> { | |
Node { | |
id: id, | |
children: Some(children), | |
} | |
} | |
fn main() { | |
let l0 = make_leaf("l0"); | |
let l1 = make_leaf("l1"); | |
let n0 = make_parent("n0", vec![l0, l1]); | |
let root = make_parent("root", vec![n0]); | |
println!("{:?}", root); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment