Skip to content

Commit b20f17c

Browse files
committed
refactor
1 parent 6c9f88f commit b20f17c

File tree

1 file changed

+10
-10
lines changed
  • rust/kindergarten-garden/src

1 file changed

+10
-10
lines changed

rust/kindergarten-garden/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub 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> {
1515
enum Plant {
1616
Grass,
1717
Clover,
18-
Radish,
19-
Violet
18+
Radishes,
19+
Violets
2020
}
2121

2222
impl 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

0 commit comments

Comments
 (0)