diff options
| author | wznmickey <first@wznmickey.com> | 2024-03-28 00:11:19 +0800 |
|---|---|---|
| committer | wznmickey <first@wznmickey.com> | 2024-03-28 00:11:19 +0800 |
| commit | dd72429af49afbfbf0c1f59f053ecc4382d074fc (patch) | |
| tree | 81cc6a54f23a6f5c8a2ca4ae221efda0910c64a4 /exercises | |
| parent | 92183a74c4c7b91459c1371bb7a68b5e4c1c23bd (diff) | |
| parent | 34d04139cd372edc0dc611ad83e056d7c4b61a73 (diff) | |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/03_if/if1.rs | 1 | ||||
| -rw-r--r-- | exercises/06_move_semantics/move_semantics2.rs | 2 | ||||
| -rw-r--r-- | exercises/06_move_semantics/move_semantics3.rs | 2 | ||||
| -rw-r--r-- | exercises/06_move_semantics/move_semantics4.rs | 2 | ||||
| -rw-r--r-- | exercises/09_strings/strings3.rs | 2 | ||||
| -rw-r--r-- | exercises/11_hashmaps/hashmaps3.rs | 9 | ||||
| -rw-r--r-- | exercises/18_iterators/iterators4.rs | 2 | ||||
| -rw-r--r-- | exercises/20_threads/threads3.rs | 12 | ||||
| -rw-r--r-- | exercises/23_conversions/from_into.rs | 18 | ||||
| -rw-r--r-- | exercises/README.md | 4 |
10 files changed, 26 insertions, 28 deletions
diff --git a/exercises/03_if/if1.rs b/exercises/03_if/if1.rs index 4734d78..d2afccf 100644 --- a/exercises/03_if/if1.rs +++ b/exercises/03_if/if1.rs @@ -6,6 +6,7 @@ pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! + // If both numbers are equal, any of them can be returned. // Do not use: // - another function call // - additional variables diff --git a/exercises/06_move_semantics/move_semantics2.rs b/exercises/06_move_semantics/move_semantics2.rs index baf6bcc..dc58be5 100644 --- a/exercises/06_move_semantics/move_semantics2.rs +++ b/exercises/06_move_semantics/move_semantics2.rs @@ -11,7 +11,7 @@ fn main() { let vec0 = vec![22, 44, 66]; - let mut vec1 = fill_vec(vec0); + let vec1 = fill_vec(vec0); assert_eq!(vec0, vec![22, 44, 66]); assert_eq!(vec1, vec![22, 44, 66, 88]); diff --git a/exercises/06_move_semantics/move_semantics3.rs b/exercises/06_move_semantics/move_semantics3.rs index 7af9e69..7152c71 100644 --- a/exercises/06_move_semantics/move_semantics3.rs +++ b/exercises/06_move_semantics/move_semantics3.rs @@ -12,7 +12,7 @@ fn main() { let vec0 = vec![22, 44, 66]; - let mut vec1 = fill_vec(vec0); + let vec1 = fill_vec(vec0); assert_eq!(vec1, vec![22, 44, 66, 88]); } diff --git a/exercises/06_move_semantics/move_semantics4.rs b/exercises/06_move_semantics/move_semantics4.rs index 80b49db..bfc917f 100644 --- a/exercises/06_move_semantics/move_semantics4.rs +++ b/exercises/06_move_semantics/move_semantics4.rs @@ -13,7 +13,7 @@ fn main() { let vec0 = vec![22, 44, 66]; - let mut vec1 = fill_vec(vec0); + let vec1 = fill_vec(vec0); assert_eq!(vec1, vec![22, 44, 66, 88]); } diff --git a/exercises/09_strings/strings3.rs b/exercises/09_strings/strings3.rs index b29f932..384e7ce 100644 --- a/exercises/09_strings/strings3.rs +++ b/exercises/09_strings/strings3.rs @@ -11,7 +11,7 @@ fn trim_me(input: &str) -> String { } fn compose_me(input: &str) -> String { - // TODO: Add " world!" to the string! There's multiple ways to do this! + // TODO: Add " world!" to the string! There are multiple ways to do this! ??? } diff --git a/exercises/11_hashmaps/hashmaps3.rs b/exercises/11_hashmaps/hashmaps3.rs index 36544ee..8d9236d 100644 --- a/exercises/11_hashmaps/hashmaps3.rs +++ b/exercises/11_hashmaps/hashmaps3.rs @@ -4,10 +4,11 @@ // the form : "<team_1_name>,<team_2_name>,<team_1_goals>,<team_2_goals>" // Example: England,France,4,2 (England scored 4 goals, France 2). // -// You have to build a scores table containing the name of the team, goals the -// team scored, and goals the team conceded. One approach to build the scores -// table is to use a Hashmap. The solution is partially written to use a -// Hashmap, complete it to pass the test. +// You have to build a scores table containing the name of the team, the total +// number of goals the team scored, and the total number of goals the team +// conceded. One approach to build the scores table is to use a Hashmap. +// The solution is partially written to use a Hashmap, +// complete it to pass the test. // // Make me pass the tests! // diff --git a/exercises/18_iterators/iterators4.rs b/exercises/18_iterators/iterators4.rs index 79e1692..3c0724e 100644 --- a/exercises/18_iterators/iterators4.rs +++ b/exercises/18_iterators/iterators4.rs @@ -8,7 +8,7 @@ pub fn factorial(num: u64) -> u64 { // Complete this function to return the factorial of num // Do not use: - // - return + // - early returns (using the `return` keyword explicitly) // Try not to use: // - imperative style loops (for, while) // - additional variables diff --git a/exercises/20_threads/threads3.rs b/exercises/20_threads/threads3.rs index 91006bb..acb97b4 100644 --- a/exercises/20_threads/threads3.rs +++ b/exercises/20_threads/threads3.rs @@ -27,22 +27,18 @@ impl Queue { } fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () { - let qc = Arc::new(q); - let qc1 = Arc::clone(&qc); - let qc2 = Arc::clone(&qc); - thread::spawn(move || { - for val in &qc1.first_half { + for val in q.first_half { println!("sending {:?}", val); - tx.send(*val).unwrap(); + tx.send(val).unwrap(); thread::sleep(Duration::from_secs(1)); } }); thread::spawn(move || { - for val in &qc2.second_half { + for val in q.second_half { println!("sending {:?}", val); - tx.send(*val).unwrap(); + tx.send(val).unwrap(); thread::sleep(Duration::from_secs(1)); } }); diff --git a/exercises/23_conversions/from_into.rs b/exercises/23_conversions/from_into.rs index 60911f3..11787c3 100644 --- a/exercises/23_conversions/from_into.rs +++ b/exercises/23_conversions/from_into.rs @@ -24,8 +24,9 @@ impl Default for Person { } } -// Your task is to complete this implementation in order for the line `let p = -// Person::from("Mark,20")` to compile Please note that you'll need to parse the + +// Your task is to complete this implementation in order for the line `let p1 = +// Person::from("Mark,20")` to compile. Please note that you'll need to parse the // age component into a `usize` with something like `"4".parse::<usize>()`. The // outcome of this needs to be handled appropriately. // @@ -43,8 +44,7 @@ impl Default for Person { // I AM NOT DONE impl From<&str> for Person { - fn from(s: &str) -> Person { - } + fn from(s: &str) -> Person {} } fn main() { @@ -127,14 +127,14 @@ mod tests { #[test] fn test_trailing_comma() { let p: Person = Person::from("Mike,32,"); - assert_eq!(p.name, "Mike"); - assert_eq!(p.age, 32); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); } #[test] fn test_trailing_comma_and_some_string() { - let p: Person = Person::from("Mike,32,man"); - assert_eq!(p.name, "Mike"); - assert_eq!(p.age, 32); + let p: Person = Person::from("Mike,32,dog"); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); } } diff --git a/exercises/README.md b/exercises/README.md index 4cb966e..237f2f1 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -17,11 +17,11 @@ | error_handling | §9 | | generics | §10 | | traits | §10.2 | -| tests | §11.1 | | lifetimes | §10.3 | +| tests | §11.1 | | iterators | §13.2-4 | -| threads | §16.1-3 | | smart_pointers | §15, §16.3 | +| threads | §16.1-3 | | macros | §19.5 | | clippy | §21.4 | | conversions | n/a | |
