From f91da817be5688f052bce317b1f70ad7176fd13b Mon Sep 17 00:00:00 2001 From: Jordan Gong Date: Sun, 20 Sep 2020 15:55:28 +0800 Subject: Loading data on the heap using box --- smart_pointer/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 smart_pointer/src/main.rs (limited to 'smart_pointer/src/main.rs') diff --git a/smart_pointer/src/main.rs b/smart_pointer/src/main.rs new file mode 100644 index 0000000..b19ab5f --- /dev/null +++ b/smart_pointer/src/main.rs @@ -0,0 +1,14 @@ +// Recursive type using boxes +enum List { + Cons(i32, Box), + 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)))))); +} -- cgit v1.2.3