Skip to content

Commit 4dadc9c

Browse files
committed
update
1 parent 68cb798 commit 4dadc9c

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

exercises/generics/generics1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a
77
// hint.
88

9-
// I AM NOT DONE
9+
1010

1111
fn main() {
12-
let mut shopping_list: Vec<?> = Vec::new();
12+
let mut shopping_list: Vec<&str> = Vec::new();
1313
shopping_list.push("milk");
1414
}

exercises/generics/generics2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a
77
// hint.
88

9-
// I AM NOT DONE
109

11-
struct Wrapper {
12-
value: u32,
10+
11+
struct Wrapper<T> {
12+
value: T,
1313
}
1414

15-
impl Wrapper {
16-
pub fn new(value: u32) -> Self {
15+
impl<T> Wrapper<T> {
16+
pub fn new(value: T) -> Self {
1717
Wrapper { value }
1818
}
1919
}

exercises/options/options1.rs

Lines changed: 9 additions & 3 deletions
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+
None
20+
} else {
21+
Some(0)
22+
}
1723
}
1824

1925
#[cfg(test)]
@@ -33,7 +39,7 @@ mod tests {
3339
fn raw_value() {
3440
// TODO: Fix this test. How do you get at the value contained in the
3541
// Option?
36-
let icecreams = maybe_icecream(12);
42+
let icecreams = maybe_icecream(12).unwrap();
3743
assert_eq!(icecreams, 5);
3844
}
3945
}

exercises/quiz3.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
//
1717
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
1818

19-
// I AM NOT DONE
2019

21-
pub struct ReportCard {
22-
pub grade: f32,
20+
21+
use std::fmt::Display;
22+
23+
pub struct ReportCard<T:Display> {
24+
pub grade: T,
2325
pub student_name: String,
2426
pub student_age: u8,
2527
}
2628

27-
impl ReportCard {
29+
impl<T:Display> ReportCard<T> {
2830
pub fn print(&self) -> String {
2931
format!("{} ({}) - achieved a grade of {}",
3032
&self.student_name, &self.student_age, &self.grade)
@@ -52,7 +54,7 @@ mod tests {
5254
fn generate_alphabetic_report_card() {
5355
// TODO: Make sure to change the grade here after you finish the exercise.
5456
let report_card = ReportCard {
55-
grade: 2.1,
57+
grade: "A+",
5658
student_name: "Gary Plotter".to_string(),
5759
student_age: 11,
5860
};

0 commit comments

Comments
 (0)