about summary refs log tree commit diff
path: root/users/wpcarro/scratch/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/rust/src')
-rw-r--r--users/wpcarro/scratch/rust/src/main.rs3
-rw-r--r--users/wpcarro/scratch/rust/src/rc/mod.rs12
2 files changed, 14 insertions, 1 deletions
diff --git a/users/wpcarro/scratch/rust/src/main.rs b/users/wpcarro/scratch/rust/src/main.rs
index 185e7236c5f6..671b33093050 100644
--- a/users/wpcarro/scratch/rust/src/main.rs
+++ b/users/wpcarro/scratch/rust/src/main.rs
@@ -3,6 +3,7 @@ use serde_json::{json, Value};
 
 mod display;
 mod json;
+mod rc;
 mod stdin;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -10,5 +11,5 @@ mod stdin;
 ////////////////////////////////////////////////////////////////////////////////
 
 fn main() {
-    stdin::example();
+    rc::example();
 }
diff --git a/users/wpcarro/scratch/rust/src/rc/mod.rs b/users/wpcarro/scratch/rust/src/rc/mod.rs
new file mode 100644
index 000000000000..67251ca6aa9b
--- /dev/null
+++ b/users/wpcarro/scratch/rust/src/rc/mod.rs
@@ -0,0 +1,12 @@
+// Playing around with Rust's "smart pointers". Starting off with a wrapper type
+// that allows multiple readers (owners?) of some data.
+
+use std::rc::Rc;
+
+pub fn example() {
+    let five = Rc::new(5);
+    let x = Rc::clone(&five);
+    let y = Rc::clone(&five);
+    let z = Rc::clone(&five);
+    println!("result: {}", *x + *y + *z)
+}