summaryrefslogtreecommitdiffstats
path: root/src/smartpointers
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-10-31 03:54:43 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-10-31 03:54:43 +0300
commit62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2 (patch)
treeb8461eda6cce3f9bbfb2261dd828077e17c7d226 /src/smartpointers
parent18ad654357d6cca34782aaa269f5e8e06cbe9241 (diff)
downloadrust-book-62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2.tar.gz
rust-book-62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2.tar.bz2
rust-book-62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2.zip
add: 7 craits
smartpointers interior_mutability threads mutex hello-async async_concurrency multi_futures
Diffstat (limited to '')
-rw-r--r--src/smartpointers/Cargo.toml6
-rw-r--r--src/smartpointers/src/main.rs16
2 files changed, 22 insertions, 0 deletions
diff --git a/src/smartpointers/Cargo.toml b/src/smartpointers/Cargo.toml
new file mode 100644
index 0000000..2a65854
--- /dev/null
+++ b/src/smartpointers/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "smartpointers"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/smartpointers/src/main.rs b/src/smartpointers/src/main.rs
new file mode 100644
index 0000000..594c5c1
--- /dev/null
+++ b/src/smartpointers/src/main.rs
@@ -0,0 +1,16 @@
+enum List {
+ Cons(i32, Rc<List>),
+ Nil,
+}
+
+use crate::List::{Cons, Nil};
+use std::rc::Rc;
+
+fn main() {
+ let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
+ println!("a have {} references", Rc::strong_count(&a));
+ let b = Cons(3, Rc::clone(&a));
+ println!("a have {} references", Rc::strong_count(&a));
+ let c = Cons(4, Rc::clone(&a));
+ println!("a have {} references", Rc::strong_count(&a));
+}