From 0133731e97f306029832c0d7e6287a85f6f043ef Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 26 Apr 2020 20:44:44 +0100 Subject: [PATCH] allow variables to have a default value of "" --- src/variable.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/variable.rs b/src/variable.rs index b0a53e5..2473bf4 100644 --- a/src/variable.rs +++ b/src/variable.rs @@ -6,9 +6,14 @@ pub struct Variable { impl From for Variable { fn from(string: String) -> Variable { - let id_value: Vec<&str> = string.split('\n').collect(); + let id_value: Vec<&str> = string.lines().collect(); let id = id_value[0].replace("VAR ", "").to_string(); - let initial_value = id_value[1].to_string(); + + let initial_value = if id_value.len() == 1 { + "".to_string() + } else { + id_value[1..].join("") + }; Variable { id, initial_value } }