File tree Expand file tree Collapse file tree 4 files changed +29
-20
lines changed
Expand file tree Collapse file tree 4 files changed +29
-20
lines changed Original file line number Diff line number Diff line change 1616
1717// Put your function here!
1818fn calculate_price_of_apples ( number : i32 ) -> i32 {
19-
20- if number > 40 {
21- number
22- } else {
23- number * 2
24- }
19+ let price_per_apple = if number > 40 { 1 } else { 2 } ;
20+ number * price_per_apple
2521}
2622
23+
2724// Don't modify this function!
2825#[ test]
2926fn verify_test ( ) {
Original file line number Diff line number Diff line change 2020//
2121// No hints this time!
2222
23- // I AM NOT DONE
24-
2523pub enum Command {
2624 Uppercase ,
2725 Trim ,
@@ -32,11 +30,23 @@ mod my_module {
3230 use super :: Command ;
3331
3432 // TODO: Complete the function signature!
35- pub fn transformer ( input : ??? ) -> ??? {
33+ pub fn transformer ( input : Vec < ( String , Command ) > ) -> Vec < String > {
3634 // TODO: Complete the output declaration!
37- let mut output: ??? = vec ! [ ] ;
35+ let mut output: Vec < String > = vec ! [ ] ;
36+
3837 for ( string, command) in input. iter ( ) {
39- // TODO: Complete the function body. You can do it!
38+ let transformed = match command {
39+ Command :: Uppercase => string. to_uppercase ( ) ,
40+ Command :: Trim => string. trim ( ) . to_string ( ) ,
41+ Command :: Append ( times) => {
42+ let mut s = string. clone ( ) ;
43+ for _ in 0 ..* times {
44+ s. push_str ( "bar" ) ;
45+ }
46+ s
47+ }
48+ } ;
49+ output. push ( transformed) ;
4050 }
4151 output
4252 }
@@ -45,7 +55,7 @@ mod my_module {
4555#[ cfg( test) ]
4656mod tests {
4757 // TODO: What do we need to import to have `transformer` in scope?
48- use ??? ;
58+ use super :: my_module :: transformer ;
4959 use super :: Command ;
5060
5161 #[ test]
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
19+ use std :: fmt :: Display ;
2020
21- pub struct ReportCard {
22- pub grade : f32 ,
21+ pub struct ReportCard < T : Display > {
22+ pub grade : T ,
2323 pub student_name : String ,
2424 pub student_age : u8 ,
2525}
2626
27- impl ReportCard {
27+ impl < T : Display > ReportCard < T > {
2828 pub fn print ( & self ) -> String {
29- format ! ( "{} ({}) - achieved a grade of {}" ,
30- & self . student_name, & self . student_age, & self . grade)
29+ format ! (
30+ "{} ({}) - achieved a grade of {}" ,
31+ & self . student_name, & self . student_age, & self . grade
32+ )
3133 }
3234}
3335
@@ -50,9 +52,8 @@ mod tests {
5052
5153 #[ test]
5254 fn generate_alphabetic_report_card ( ) {
53- // TODO: Make sure to change the grade here after you finish the exercise.
5455 let report_card = ReportCard {
55- grade : 2.1 ,
56+ grade : "A+" ,
5657 student_name : "Gary Plotter" . to_string ( ) ,
5758 student_age : 11 ,
5859 } ;
Original file line number Diff line number Diff line change @@ -10,3 +10,4 @@ fn main() {
1010 let x = 5 ;
1111 println ! ( "x has the value {}" , x) ;
1212}
13+
You can’t perform that action at this time.
0 commit comments