Skip to content

Commit

Permalink
Take care of all the .clones called on smart pointers
Browse files Browse the repository at this point in the history
Fixes #729.
  • Loading branch information
carols10cents committed Sep 18, 2017
1 parent a948a75 commit ad8d0ab
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions second-edition/src/ch15-04-rc.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ a bit. /Carol -->
fn main() {
let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
println!("count after creating a = {}", Rc::strong_count(&a));
let b = Cons(3, a.clone());
let b = Cons(3, Rc::clone(&a));
println!("count after creating b = {}", Rc::strong_count(&a));
{
let c = Cons(4, a.clone());
let c = Cons(4, Rc::clone(&a));
println!("count after creating c = {}", Rc::strong_count(&a));
}
println!("count after c goes out of scope = {}", Rc::strong_count(&a));
Expand Down
2 changes: 1 addition & 1 deletion second-edition/src/ch16-02-message-passing.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ cloning the transmitting half of the channel, as shown in Listing 16-11:
// ...snip...
let (tx, rx) = mpsc::channel();

let tx1 = tx.clone();
let tx1 = mpsc::Sender::clone(&tx);
thread::spawn(move || {
let vals = vec![
String::from("hi"),
Expand Down
4 changes: 2 additions & 2 deletions second-edition/src/ch16-03-shared-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn main() {
let mut handles = vec![];
for _ in 0..10 {
let counter = counter.clone();
let counter = Rc::clone(&counter);
let handle = thread::spawn(move || {
let mut num = counter.lock().unwrap();
Expand Down Expand Up @@ -379,7 +379,7 @@ fn main() {
let mut handles = vec![];

for _ in 0..10 {
let counter = counter.clone();
let counter = Arc::clone(&counter);
let handle = thread::spawn(move || {
let mut num = counter.lock().unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl ThreadPool {
let mut workers = Vec::with_capacity(size);

for id in 0..size {
workers.push(Worker::new(id, receiver.clone()));
workers.push(Worker::new(id, Arc::clone(&receiver)));
}

ThreadPool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl ThreadPool {
let mut workers = Vec::with_capacity(size);

for id in 0..size {
workers.push(Worker::new(id, receiver.clone()));
workers.push(Worker::new(id, Arc::clone(&receiver)));
}

ThreadPool {
Expand Down

0 comments on commit ad8d0ab

Please sign in to comment.