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 1
1
pub fn plants ( diagram : & str , name : & str ) -> Vec < & ' static str > {
2
- let student = parse_student ( name) ;
3
2
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 " ) {
6
6
for index in student. indices ( ) {
7
7
let encoding = line. chars ( ) . nth ( index) . unwrap ( ) ;
8
8
let plant = get_plant ( encoding) ;
@@ -15,17 +15,17 @@ pub fn plants(diagram: &str, name: &str) -> Vec<&'static str> {
15
15
enum Plant {
16
16
Grass ,
17
17
Clover ,
18
- Radish ,
19
- Violet
18
+ Radishes ,
19
+ Violets
20
20
}
21
21
22
22
impl Plant {
23
23
fn string ( & self ) -> & ' static str {
24
24
match self {
25
25
Plant :: Grass => "grass" ,
26
26
Plant :: Clover => "clover" ,
27
- Plant :: Radish => "radishes" ,
28
- Plant :: Violet => "violets" ,
27
+ Plant :: Radishes => "radishes" ,
28
+ Plant :: Violets => "violets" ,
29
29
}
30
30
}
31
31
}
@@ -34,9 +34,9 @@ fn get_plant(encoding: char) -> Plant {
34
34
return match encoding {
35
35
'G' => Plant :: Grass ,
36
36
'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" )
40
40
}
41
41
}
42
42
You can’t perform that action at this time.
0 commit comments