File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
rust/kindergarten-garden/src Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change 11pub fn plants ( diagram : & str , name : & str ) -> Vec < & ' static str > {
2- let student = parse_student ( name) ;
32 let mut result = vec ! [ ] ;
4- let lines = diagram. split ( "\n " ) ;
5- for line in lines {
3+ let student = parse_student ( name) ;
4+
5+ for line in diagram. split ( "\n " ) {
66 for index in student. indices ( ) {
77 let encoding = line. chars ( ) . nth ( index) . unwrap ( ) ;
88 let plant = get_plant ( encoding) ;
@@ -15,17 +15,17 @@ pub fn plants(diagram: &str, name: &str) -> Vec<&'static str> {
1515enum Plant {
1616 Grass ,
1717 Clover ,
18- Radish ,
19- Violet
18+ Radishes ,
19+ Violets
2020}
2121
2222impl Plant {
2323 fn string ( & self ) -> & ' static str {
2424 match self {
2525 Plant :: Grass => "grass" ,
2626 Plant :: Clover => "clover" ,
27- Plant :: Radish => "radishes" ,
28- Plant :: Violet => "violets" ,
27+ Plant :: Radishes => "radishes" ,
28+ Plant :: Violets => "violets" ,
2929 }
3030 }
3131}
@@ -34,9 +34,9 @@ fn get_plant(encoding: char) -> Plant {
3434 return match encoding {
3535 'G' => Plant :: Grass ,
3636 'C' => Plant :: Clover ,
37- 'R' => Plant :: Radish ,
38- 'V' => Plant :: Violet ,
39- _ => Plant :: Grass // TODO: replace this with an error
37+ 'R' => Plant :: Radishes ,
38+ 'V' => Plant :: Violets ,
39+ _ => panic ! ( "Invalid plant encoding" )
4040 }
4141}
4242
You can’t perform that action at this time.
0 commit comments