File tree Expand file tree Collapse file tree 4 files changed +23
-15
lines changed Expand file tree Collapse file tree 4 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 66// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a
77// hint.
88
9- // I AM NOT DONE
9+
1010
1111fn main ( ) {
12- let mut shopping_list: Vec < ? > = Vec :: new ( ) ;
12+ let mut shopping_list: Vec < & str > = Vec :: new ( ) ;
1313 shopping_list. push ( "milk" ) ;
1414}
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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 } ;
You can’t perform that action at this time.
0 commit comments