Browse Source

Replace ugly if/else with match block

master
Jim Infield 3 years ago
parent
commit
1f4704be95
  1. 18
      src/lib.rs

18
src/lib.rs

@ -24,17 +24,11 @@ pub fn reply(message: &str) -> &str {
if u > l { shouted = true; }
if u+l+n == 0 { silence = true; }
if shouted {
if question {
return "Calm down, I know what I'm doing!"
} else {
return "Whoa, chill out!"
}
} else if question {
return "Sure."
} else if silence {
return "Fine. Be that way!"
} else {
return "Whatever."
match (question,shouted, silence) {
(true,true, _ ) => "Calm down, I know what I'm doing!",
(true, _ , _ ) => "Sure.",
( _ ,true, _ ) => "Whoa, chill out!",
( _ , _ ,true) => "Fine. Be that way!",
( _ , _ , _ ) => "Whatever.",
}
}
Loading…
Cancel
Save