diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2020-09-20 15:55:28 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2020-09-20 15:55:28 +0800 |
commit | f91da817be5688f052bce317b1f70ad7176fd13b (patch) | |
tree | 29f2ebd6f5f63dc6f960d3935a469a7dbd839dcf /smart_pointer/src | |
parent | 680c8633e6206085ad417c6055e17f6d30f462a4 (diff) |
Loading data on the heap using box
Diffstat (limited to 'smart_pointer/src')
-rw-r--r-- | smart_pointer/src/main.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<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)))))); +} |