Skip to content

Commit 5d9bf0c

Browse files
committed
update1
1 parent 08cea93 commit 5d9bf0c

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

exercises/options/options1.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
// Execute `rustlings hint options1` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
// This function returns how much icecream there is left in the fridge.
97
// If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them
108
// all, so there'll be no more left :(
119
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
1210
// We use the 24-hour system here, so 10PM is a value of 22 and 12AM is a
1311
// value of 0 The Option output should gracefully handle cases where
1412
// time_of_day > 23.
15-
// TODO: Complete the function body - remember to return an Option!
16-
???
13+
if time_of_day > 23 {
14+
None
15+
} else if time_of_day < 22 {
16+
Some(5)
17+
} else {
18+
Some(0)
19+
}
1720
}
1821

1922
#[cfg(test)]
@@ -34,6 +37,6 @@ mod tests {
3437
// TODO: Fix this test. How do you get at the value contained in the
3538
// Option?
3639
let icecreams = maybe_icecream(12);
37-
assert_eq!(icecreams, 5);
40+
assert_eq!(icecreams.unwrap(), 5);
3841
}
3942
}

exercises/options/options2.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Execute `rustlings hint options2` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
#[cfg(test)]
97
mod tests {
108
#[test]
@@ -13,7 +11,7 @@ mod tests {
1311
let optional_target = Some(target);
1412

1513
// TODO: Make this an if let statement whose value is "Some" type
16-
word = optional_target {
14+
if let Some(word) = optional_target {
1715
assert_eq!(word, target);
1816
}
1917
}
@@ -32,7 +30,7 @@ mod tests {
3230
// TODO: make this a while let statement - remember that vector.pop also
3331
// adds another layer of Option<T>. You can stack `Option<T>`s into
3432
// while let and if let.
35-
integer = optional_integers.pop() {
33+
while let Some(Some(integer)) = optional_integers.pop() {
3634
assert_eq!(integer, cursor);
3735
cursor -= 1;
3836
}

exercises/options/options3.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Execute `rustlings hint options3` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
struct Point {
97
x: i32,
108
y: i32,
@@ -13,7 +11,7 @@ struct Point {
1311
fn main() {
1412
let y: Option<Point> = Some(Point { x: 100, y: 200 });
1513

16-
match y {
14+
match &y {
1715
Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y),
1816
_ => panic!("no match!"),
1917
}

exercises/primitive_types/primitive_types5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
fn main() {
1010
let cat = ("Furry McFurson", 3.5);
11-
let /* your pattern here */(name, age) = cat;
11+
let (name, age) = cat;
1212

1313
println!("{} is {} years old.", name, age);
1414
}

0 commit comments

Comments
 (0)