Skip to content

Commit 3e74703

Browse files
04092003
1 parent 9d17850 commit 3e74703

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

exercises/smart_pointers/cow1.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
//
1313
// Execute `rustlings hint cow1` or use the `hint` watch subcommand for a hint.
1414

15-
// I AM NOT DONE
16-
1715
use std::borrow::Cow;
1816

17+
// 接受一个可变的引用,返回一个可变的引用。它会遍历输入的切片,并将所有负数转换为正数。
1918
fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
2019
for i in 0..input.len() {
2120
let v = input[i];
@@ -48,7 +47,8 @@ mod tests {
4847
let slice = [0, 1, 2];
4948
let mut input = Cow::from(&slice[..]);
5049
match abs_all(&mut input) {
51-
// TODO
50+
Cow::Borrowed(_) => Ok(()),
51+
_ => Err("Expected borrowed value"),
5252
}
5353
}
5454

@@ -60,7 +60,8 @@ mod tests {
6060
let slice = vec![0, 1, 2];
6161
let mut input = Cow::from(slice);
6262
match abs_all(&mut input) {
63-
// TODO
63+
Cow::Owned(_) => Ok(()),
64+
_ => Err("Expected owned value"),
6465
}
6566
}
6667

@@ -72,7 +73,8 @@ mod tests {
7273
let slice = vec![-1, 0, 1];
7374
let mut input = Cow::from(slice);
7475
match abs_all(&mut input) {
75-
// TODO
76+
Cow::Owned(_) => Ok(()),
77+
_ => Err("Expected owned value"),
7678
}
7779
}
7880
}

exercises/threads/threads1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// Execute `rustlings hint threads1` or use the `hint` watch subcommand for a
99
// hint.
1010

11-
// I AM NOT DONE
12-
1311
use std::thread;
1412
use std::time::{Duration, Instant};
1513

@@ -27,6 +25,7 @@ fn main() {
2725
let mut results: Vec<u128> = vec![];
2826
for handle in handles {
2927
// TODO: a struct is returned from thread::spawn, can you use it?
28+
results.push(handle.join().expect("Oh no! The thread panicked!"));
3029
}
3130

3231
if results.len() != 10 {

0 commit comments

Comments
 (0)