From 659eaee14ecf688814cf8bff4294dc28bb85ac2a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 23 Apr 2017 03:42:50 +0100 Subject: [PATCH] data_forms: Simplify the FromStr using match. --- src/data_forms.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/data_forms.rs b/src/data_forms.rs index dd9b3e11..f25c8818 100644 --- a/src/data_forms.rs +++ b/src/data_forms.rs @@ -30,17 +30,14 @@ impl FromStr for DataFormType { type Err = Error; fn from_str(s: &str) -> Result { - if s == "cancel" { - Ok(DataFormType::Cancel) - } else if s == "form" { - Ok(DataFormType::Form) - } else if s == "result" { - Ok(DataFormType::Result_) - } else if s == "submit" { - Ok(DataFormType::Submit) - } else { - Err(Error::ParseError("Unknown data form type.")) - } + Ok(match s { + "cancel" => DataFormType::Cancel, + "form" => DataFormType::Form, + "result" => DataFormType::Result_, + "submit" => DataFormType::Submit, + + _ => return Err(Error::ParseError("Unknown data form type.")), + }) } }