summaryrefslogtreecommitdiff
path: root/smart_pointer/src/main.rs
blob: b19ab5f360d911bbfe4375fbcdb3551c23301f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Recursive type using boxes
enum List {
    Cons(i32, Box<List>),
    Nil,
}

fn main() {
    // Storing `i32` value on heap
    let b = Box::new(5);
    println!("b = {}", b);

    use crate::List::{Cons, Nil};
    let list = Cons(1, Box::new(Cons(2, Box::new(Cons(3, Box::new(Nil))))));
}