Skip to content

Instantly share code, notes, and snippets.

@psyomn
Created November 1, 2015 22:21
Show Gist options
  • Save psyomn/c08d4fae2c1e58199daa to your computer and use it in GitHub Desktop.
Save psyomn/c08d4fae2c1e58199daa to your computer and use it in GitHub Desktop.
Recursive trees in Rust!
//! Recursive enumerable types! Freaking cool!
#[derive(Debug)]
pub enum BinTree<T> {
Value(T,
Option<Box<BinTree<T>>>,
Option<Box<BinTree<T>>>),
}
fn main() -> () {
let tree: BinTree<u32> =
BinTree::Value(1,
Some(Box::new(BinTree::Value(2, None, None))),
Some(
Box::new(BinTree::Value(3,
Some(Box::new(BinTree::Value(4, None, None))), None)),
),
);
println!("{:#?}", tree);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment