File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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
10-
119fn main ( ) {
12- let mut shopping_list: Vec < ? > = Vec :: new ( ) ;
10+ let mut shopping_list: Vec < & str > = Vec :: new ( ) ;
1311 shopping_list. push ( "milk" ) ;
14- }
12+ }
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
10-
11- struct Wrapper {
12- value : u32 ,
9+ struct Wrapper < T > {
10+ value : T ,
1311}
1412
15- impl Wrapper {
16- pub fn new ( value : u32 ) -> Self {
13+ impl < T > Wrapper < T > {
14+ pub fn new ( value : T ) -> Self {
1715 Wrapper { value }
1816 }
1917}
@@ -31,4 +29,4 @@ mod tests {
3129 fn store_str_in_wrapper ( ) {
3230 assert_eq ! ( Wrapper :: new( "Foo" ) . value, "Foo" ) ;
3331 }
34- }
32+ }
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
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 :(
@@ -13,7 +11,13 @@ fn maybe_icecream(time_of_day: u16) -> Option<u16> {
1311 // value of 0 The Option output should gracefully handle cases where
1412 // time_of_day > 23.
1513 // TODO: Complete the function body - remember to return an Option!
16- ???
14+ if time_of_day > 23 {
15+ None
16+ } else if time_of_day < 22 {
17+ Some ( 5 )
18+ } else {
19+ Some ( 0 )
20+ }
1721}
1822
1923#[ cfg( test) ]
@@ -33,7 +37,7 @@ mod tests {
3337 fn raw_value ( ) {
3438 // TODO: Fix this test. How do you get at the value contained in the
3539 // Option?
36- let icecreams = maybe_icecream ( 12 ) ;
40+ let icecreams = maybe_icecream ( 12 ) . unwrap ( ) ;
3741 assert_eq ! ( icecreams, 5 ) ;
3842 }
3943}
Original file line number Diff line number Diff line change 88// Execute `rustlings hint traits3` or use the `hint` watch subcommand for a
99// hint.
1010
11- // I AM NOT DONE
12-
1311pub trait Licensed {
14- fn licensing_info ( & self ) -> String ;
12+ fn licensing_info ( & self ) -> String {
13+ String :: from ( "Some information" )
14+ }
1515}
1616
1717struct SomeSoftware {
@@ -39,4 +39,4 @@ mod tests {
3939 assert_eq ! ( some_software. licensing_info( ) , licensing_info) ;
4040 assert_eq ! ( other_software. licensing_info( ) , licensing_info) ;
4141 }
42- }
42+ }
Original file line number Diff line number Diff line change 77// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a
88// hint.
99
10- // I AM NOT DONE
11-
1210pub trait Licensed {
1311 fn licensing_info ( & self ) -> String {
1412 "some information" . to_string ( )
@@ -23,7 +21,7 @@ impl Licensed for SomeSoftware {}
2321impl Licensed for OtherSoftware { }
2422
2523// YOU MAY ONLY CHANGE THE NEXT LINE
26- fn compare_license_types ( software : ?? , software_two : ?? ) -> bool {
24+ fn compare_license_types ( software : impl Licensed , software_two : impl Licensed ) -> bool {
2725 software. licensing_info ( ) == software_two. licensing_info ( )
2826}
2927
@@ -46,4 +44,4 @@ mod tests {
4644
4745 assert ! ( compare_license_types( other_software, some_software) ) ;
4846 }
49- }
47+ }
You can’t perform that action at this time.
0 commit comments