Skip to content

Commit ad8d0ab

Browse files
committed
Take care of all the .clones called on smart pointers
Fixes #729.
1 parent a948a75 commit ad8d0ab

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

second-edition/src/ch15-04-rc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ a bit. /Carol -->
192192
fn main() {
193193
let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
194194
println!("count after creating a = {}", Rc::strong_count(&a));
195-
let b = Cons(3, a.clone());
195+
let b = Cons(3, Rc::clone(&a));
196196
println!("count after creating b = {}", Rc::strong_count(&a));
197197
{
198-
let c = Cons(4, a.clone());
198+
let c = Cons(4, Rc::clone(&a));
199199
println!("count after creating c = {}", Rc::strong_count(&a));
200200
}
201201
println!("count after c goes out of scope = {}", Rc::strong_count(&a));

second-edition/src/ch16-02-message-passing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ cloning the transmitting half of the channel, as shown in Listing 16-11:
264264
// ...snip...
265265
let (tx, rx) = mpsc::channel();
266266

267-
let tx1 = tx.clone();
267+
let tx1 = mpsc::Sender::clone(&tx);
268268
thread::spawn(move || {
269269
let vals = vec![
270270
String::from("hi"),

second-edition/src/ch16-03-shared-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn main() {
291291
let mut handles = vec![];
292292
293293
for _ in 0..10 {
294-
let counter = counter.clone();
294+
let counter = Rc::clone(&counter);
295295
let handle = thread::spawn(move || {
296296
let mut num = counter.lock().unwrap();
297297
@@ -379,7 +379,7 @@ fn main() {
379379
let mut handles = vec![];
380380

381381
for _ in 0..10 {
382-
let counter = counter.clone();
382+
let counter = Arc::clone(&counter);
383383
let handle = thread::spawn(move || {
384384
let mut num = counter.lock().unwrap();
385385

second-edition/src/ch20-05-sending-requests-via-channels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl ThreadPool {
203203
let mut workers = Vec::with_capacity(size);
204204

205205
for id in 0..size {
206-
workers.push(Worker::new(id, receiver.clone()));
206+
workers.push(Worker::new(id, Arc::clone(&receiver)));
207207
}
208208

209209
ThreadPool {

second-edition/src/ch20-06-graceful-shutdown-and-cleanup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl ThreadPool {
494494
let mut workers = Vec::with_capacity(size);
495495

496496
for id in 0..size {
497-
workers.push(Worker::new(id, receiver.clone()));
497+
workers.push(Worker::new(id, Arc::clone(&receiver)));
498498
}
499499

500500
ThreadPool {

0 commit comments

Comments
 (0)