diff options
Diffstat (limited to 'smart_pointer/src/main.rs')
-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)))))); +} |