Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 26, 2019 22:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/c7d90e914d8449562e4e8cc9d3eca2ce to your computer and use it in GitHub Desktop.
Save rust-play/c7d90e914d8449562e4e8cc9d3eca2ce to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#[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