From: Ralf Jung Date: Sun, 6 Mar 2016 11:02:20 +0000 (+0100) Subject: fix warnings when compiling with rust 1.7 X-Git-Url: https://git.ralfj.de/rust-101.git/commitdiff_plain/3530068c5bbcbd9185757369dd23b9edb3bbc9ad?ds=sidebyside fix warnings when compiling with rust 1.7 --- diff --git a/solutions/src/counter.rs b/solutions/src/counter.rs index 319058e..acf8293 100644 --- a/solutions/src/counter.rs +++ b/solutions/src/counter.rs @@ -1,5 +1,6 @@ use std::sync::{Arc, RwLock}; use std::thread; +use std::time::Duration; #[derive(Clone)] pub struct ConcurrentCounter(Arc>); @@ -36,7 +37,7 @@ pub fn main() { let counter1 = counter.clone(); let handle1 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(15); + thread::sleep(Duration::from_millis(15)); counter1.increment(2); } }); @@ -45,14 +46,14 @@ pub fn main() { let counter2 = counter.clone(); let handle2 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(20); + thread::sleep(Duration::from_millis(20)); counter2.increment(3); } }); // Now we want to watch the threads working on the counter. for _ in 0..50 { - thread::sleep_ms(5); + thread::sleep(Duration::from_millis(5)); println!("Current value: {}", counter.get()); } diff --git a/src/part03.rs b/src/part03.rs index 513148b..3a35aa7 100644 --- a/src/part03.rs +++ b/src/part03.rs @@ -104,7 +104,7 @@ pub fn main() { // Notice that I called the function on `SomethingOrNothing` `print2` to disambiguate from the `print` defined previously. // // *Hint*: There is a macro `print!` for printing without appending a newline. -trait Print { +pub trait Print { /* Add things here */ } impl SomethingOrNothing { diff --git a/src/part15.rs b/src/part15.rs index 79fd9b4..f60a481 100644 --- a/src/part15.rs +++ b/src/part15.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex}; use std::thread; +use std::time::Duration; //@ We already saw that we can use `Arc` to share memory between threads. However, `Arc` can only provide *read-only* //@ access to memory: Since there is aliasing, Rust cannot, in general, permit mutation. To implement shared-memory @@ -70,7 +71,7 @@ pub fn main() { let counter1 = counter.clone(); let handle1 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(15); + thread::sleep(Duration::from_millis(15)); counter1.increment(2); } }); @@ -79,14 +80,14 @@ pub fn main() { let counter2 = counter.clone(); let handle2 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(20); + thread::sleep(Duration::from_millis(20)); counter2.increment(3); } }); // Now we watch the threads working on the counter. for _ in 0..50 { - thread::sleep_ms(5); + thread::sleep(Duration::from_millis(5)); println!("Current value: {}", counter.get()); }