From 2d9ee01a8b35efe8244c076bd69bd03470b3fc05 Mon Sep 17 00:00:00 2001
From: Niv <nivkner@zoho.com>
Date: Fri, 8 Sep 2017 20:14:03 +0300
Subject: [PATCH] refactor `match` statements

---
 src/shell/assignments.rs | 49 +++++++++++++++-------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)

diff --git a/src/shell/assignments.rs b/src/shell/assignments.rs
index 168713ea..18809e54 100644
--- a/src/shell/assignments.rs
+++ b/src/shell/assignments.rs
@@ -62,38 +62,31 @@ impl<'a> VariableStore for Shell<'a> {
                 for action in assignment_actions {
                     match action {
                         Ok(Action::UpdateArray(key, Operator::Equal, expression)) => {
-                            let values = match value_check(self, &expression, key.kind) {
-                                Ok(values) => match values {
-                                    ReturnValue::Vector(values) => values,
-                                    _ => unreachable!()
-                                }
+                            match value_check(self, &expression, key.kind) {
+                                Ok(ReturnValue::Vector(values)) => self.variables.set_array(key.name, values),
                                 Err(why) => {
                                     eprintln!("ion: assignment error: {}", why);
                                     return FAILURE;
                                 }
-                            };
-                            self.variables.set_array(key.name, values)
+                                _ => unreachable!()
+                            }
                         }
                         Ok(Action::UpdateArray(..)) => {
                             eprintln!("ion: arithmetic operators on array expressions aren't supported yet.");
                             return FAILURE;
                         }
                         Ok(Action::UpdateString(key, operator, expression)) => {
-                            let value = match value_check(self, &expression, key.kind) {
-                                Ok(value) => value,
+                            match value_check(self, &expression, key.kind) {
+                                Ok(ReturnValue::Str(value)) => {
+                                    if !integer_math(self, key, operator, &value) {
+                                        return FAILURE;
+                                    }
+                                }
                                 Err(why) => {
                                     eprintln!("ion: assignment error: {}", why);
                                     return FAILURE;
                                 }
-                            };
-
-                            let value = match value {
-                                ReturnValue::Str(value) => value,
                                 _ => unreachable!()
-                            };
-
-                            if !integer_math(self, key, operator, &value) {
-                                return FAILURE;
                             }
                         }
                         Err(why) => {
@@ -123,14 +116,12 @@ impl<'a> VariableStore for Shell<'a> {
                     match action {
                         Ok(Action::UpdateArray(key, Operator::Equal, expression)) => {
                             match value_check(self, &expression, key.kind) {
-                                Ok(values) => match values {
-                                    ReturnValue::Vector(values) => env::set_var(key.name, values.join(" ")),
-                                    _ => unreachable!()
-                                }
+                                Ok(ReturnValue::Vector(values)) => env::set_var(key.name, values.join(" ")),
                                 Err(why) => {
                                     eprintln!("ion: assignment error: {}", why);
                                     return FAILURE;
                                 }
+                                _ => unreachable!()
                             }
                         }
                         Ok(Action::UpdateArray(..)) => {
@@ -138,21 +129,17 @@ impl<'a> VariableStore for Shell<'a> {
                             return FAILURE;
                         }
                         Ok(Action::UpdateString(key, operator, expression)) => {
-                            let value = match value_check(self, &expression, key.kind) {
-                                Ok(value) => value,
+                            match value_check(self, &expression, key.kind) {
+                                Ok(ReturnValue::Str(value)) => {
+                                    if !integer_math_export(&self, key, operator, &value) {
+                                        return FAILURE;
+                                    }
+                                }
                                 Err(why) => {
                                     eprintln!("ion: assignment error: {}", why);
                                     return FAILURE;
                                 }
-                            };
-
-                            let value = match value {
-                                ReturnValue::Str(value) => value,
                                 _ => unreachable!()
-                            };
-
-                            if !integer_math_export(&self, key, operator, &value) {
-                                return FAILURE;
                             }
                         }
                         Err(why) => {
-- 
GitLab