From 63039666b0aa36f40b15b8bdd740154e7bdf6d51 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 14 Oct 2019 07:37:34 +0200 Subject: [PATCH] Changes from_ssv_to_string_value to return an Option. --- src/commands/from_ssv.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/commands/from_ssv.rs b/src/commands/from_ssv.rs index 2f3f574fb3..3232fd1e3e 100644 --- a/src/commands/from_ssv.rs +++ b/src/commands/from_ssv.rs @@ -37,12 +37,11 @@ fn from_ssv_string_to_value( s: &str, headerless: bool, tag: impl Into, -) -> Result, &str> { +) -> Option> { let mut lines = s.lines(); let headers = lines - .next() - .expect("No content.") + .next()? .split_whitespace() .map(|s| s.to_owned()) .collect::>(); @@ -69,7 +68,7 @@ fn from_ssv_string_to_value( }) .collect(); - Ok(Tagged::from_item(Value::Table(rows), tag)) + Some(Tagged::from_item(Value::Table(rows), tag)) } fn from_ssv( @@ -101,13 +100,13 @@ fn from_ssv( } match from_ssv_string_to_value(&concat_string, headerless, name) { - Ok(x) => match x { + Some(x) => match x { Tagged { item: Value::Table(list), ..} => { for l in list { yield ReturnSuccess::value(l) } } x => yield ReturnSuccess::value(x) }, - Err(_) => if let Some(last_tag) = latest_tag { + None => if let Some(last_tag) = latest_tag { yield Err(ShellError::labeled_error_with_secondary( "Could not parse as SSV", "input cannot be parsed ssv", @@ -115,7 +114,7 @@ fn from_ssv( "value originates from here", last_tag, )) - } + }, } };