Skip to content

Commit 29047d2

Browse files
committed
update
1 parent 8d3d14d commit 29047d2

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

exercises/options/options1.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Execute `rustlings hint options1` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
6+
77

88
// This function returns how much icecream there is left in the fridge.
99
// If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them
@@ -13,7 +13,13 @@ fn maybe_icecream(time_of_day: u16) -> Option<u16> {
1313
// value of 0 The Option output should gracefully handle cases where
1414
// time_of_day > 23.
1515
// TODO: Complete the function body - remember to return an Option!
16-
???
16+
if time_of_day < 22 {
17+
Some(5)
18+
} else if time_of_day <= 23{
19+
Some(0)
20+
} else {
21+
None
22+
}
1723
}
1824

1925
#[cfg(test)]
@@ -34,6 +40,6 @@ mod tests {
3440
// TODO: Fix this test. How do you get at the value contained in the
3541
// Option?
3642
let icecreams = maybe_icecream(12);
37-
assert_eq!(icecreams, 5);
43+
assert_eq!(icecreams.unwrap(), 5);
3844
}
3945
}

exercises/options/options2.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Execute `rustlings hint options2` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
6+
77

88
#[cfg(test)]
99
mod tests {
@@ -13,9 +13,9 @@ mod tests {
1313
let optional_target = Some(target);
1414

1515
// TODO: Make this an if let statement whose value is "Some" type
16-
word = optional_target {
17-
assert_eq!(word, target);
18-
}
16+
if let Some(word) = optional_target {
17+
assert_eq!(word, target)
18+
};
1919
}
2020

2121
#[test]
@@ -32,10 +32,10 @@ mod tests {
3232
// TODO: make this a while let statement - remember that vector.pop also
3333
// adds another layer of Option<T>. You can stack `Option<T>`s into
3434
// while let and if let.
35-
integer = optional_integers.pop() {
35+
while let Some(Some(integer)) = optional_integers.pop() {
3636
assert_eq!(integer, cursor);
3737
cursor -= 1;
38-
}
38+
};
3939

4040
assert_eq!(cursor, 0);
4141
}

exercises/options/options3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Execute `rustlings hint options3` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
6+
77

88
struct Point {
99
x: i32,
@@ -14,7 +14,7 @@ fn main() {
1414
let y: Option<Point> = Some(Point { x: 100, y: 200 });
1515

1616
match y {
17-
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
17+
Some(ref p) => println!("Co-ordinates are {},{} ", p.x, p.y),
1818
_ => panic!("no match!"),
1919
}
2020
y; // Fix without deleting this line.

0 commit comments

Comments
 (0)