summaryrefslogtreecommitdiff
path: root/smart_pointer
diff options
context:
space:
mode:
Diffstat (limited to 'smart_pointer')
-rw-r--r--smart_pointer/.gitignore18
-rw-r--r--smart_pointer/Cargo.toml9
-rw-r--r--smart_pointer/src/main.rs14
3 files changed, 41 insertions, 0 deletions
diff --git a/smart_pointer/.gitignore b/smart_pointer/.gitignore
new file mode 100644
index 0000000..e629269
--- /dev/null
+++ b/smart_pointer/.gitignore
@@ -0,0 +1,18 @@
+
+# Created by https://www.toptal.com/developers/gitignore/api/rust
+# Edit at https://www.toptal.com/developers/gitignore?templates=rust
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# End of https://www.toptal.com/developers/gitignore/api/rust
+
diff --git a/smart_pointer/Cargo.toml b/smart_pointer/Cargo.toml
new file mode 100644
index 0000000..cdc8b9b
--- /dev/null
+++ b/smart_pointer/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "smart_pointer"
+version = "0.1.0"
+authors = ["Jordan Gong <jordan.gong@protonmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
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))))));
+}