From 7c0a830d8499a48ecd7ac9e795d16c12a6a7b3df Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 15 Jul 2020 03:51:41 -0400 Subject: [PATCH] Match cleanup (#2184) * Use `unwrap_or()` to remove `match` * Use `?` for error propogation, and remove `match` --- crates/nu-cli/src/cli.rs | 5 +---- crates/nu-cli/src/commands/str_/capitalize.rs | 5 +---- crates/nu-cli/src/commands/str_/downcase.rs | 5 +---- crates/nu-cli/src/commands/str_/find_replace.rs | 5 +---- crates/nu-cli/src/commands/str_/from.rs | 5 +---- crates/nu-cli/src/commands/str_/set.rs | 5 +---- crates/nu-cli/src/commands/str_/substring.rs | 5 +---- crates/nu-cli/src/commands/str_/to_datetime.rs | 5 +---- crates/nu-cli/src/commands/str_/to_decimal.rs | 5 +---- crates/nu-cli/src/commands/str_/to_integer.rs | 5 +---- crates/nu-cli/src/commands/str_/trim.rs | 5 +---- crates/nu-cli/src/commands/str_/upcase.rs | 5 +---- crates/nu-cli/src/utils.rs | 5 +---- 13 files changed, 13 insertions(+), 52 deletions(-) diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 21e33da527..56c2eda450 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -149,10 +149,7 @@ pub fn load_plugins(context: &mut Context) -> Result<(), ShellError> { .map(|path| { let bin_name = { if let Some(name) = path.file_name() { - match name.to_str() { - Some(raw) => raw, - None => "", - } + name.to_str().unwrap_or("") } else { "" } diff --git a/crates/nu-cli/src/commands/str_/capitalize.rs b/crates/nu-cli/src/commands/str_/capitalize.rs index 3b2c515481..0e1f38172f 100644 --- a/crates/nu-cli/src/commands/str_/capitalize.rs +++ b/crates/nu-cli/src/commands/str_/capitalize.rs @@ -62,10 +62,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/downcase.rs b/crates/nu-cli/src/commands/str_/downcase.rs index 0e8ca216e1..3ac9694e4c 100644 --- a/crates/nu-cli/src/commands/str_/downcase.rs +++ b/crates/nu-cli/src/commands/str_/downcase.rs @@ -62,10 +62,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/find_replace.rs b/crates/nu-cli/src/commands/str_/find_replace.rs index c2ac63a0d7..e6826d55db 100644 --- a/crates/nu-cli/src/commands/str_/find_replace.rs +++ b/crates/nu-cli/src/commands/str_/find_replace.rs @@ -80,10 +80,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, &options, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, &options, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/from.rs b/crates/nu-cli/src/commands/str_/from.rs index 3fe74e2766..e0727f514e 100644 --- a/crates/nu-cli/src/commands/str_/from.rs +++ b/crates/nu-cli/src/commands/str_/from.rs @@ -96,10 +96,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag(), digits, group_digits) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag(), digits, group_digits)?) } else { let mut ret = v; for path in &column_paths { diff --git a/crates/nu-cli/src/commands/str_/set.rs b/crates/nu-cli/src/commands/str_/set.rs index 809fab0aee..0f74dbcc59 100644 --- a/crates/nu-cli/src/commands/str_/set.rs +++ b/crates/nu-cli/src/commands/str_/set.rs @@ -73,10 +73,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, &options, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, &options, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/substring.rs b/crates/nu-cli/src/commands/str_/substring.rs index 1f4ed5a1a0..f7823474db 100644 --- a/crates/nu-cli/src/commands/str_/substring.rs +++ b/crates/nu-cli/src/commands/str_/substring.rs @@ -108,10 +108,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, &options, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, &options, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/to_datetime.rs b/crates/nu-cli/src/commands/str_/to_datetime.rs index 8909ddccb7..938572e8d5 100644 --- a/crates/nu-cli/src/commands/str_/to_datetime.rs +++ b/crates/nu-cli/src/commands/str_/to_datetime.rs @@ -81,10 +81,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, &options, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, &options, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/to_decimal.rs b/crates/nu-cli/src/commands/str_/to_decimal.rs index e07d0e08d0..74772a8324 100644 --- a/crates/nu-cli/src/commands/str_/to_decimal.rs +++ b/crates/nu-cli/src/commands/str_/to_decimal.rs @@ -65,10 +65,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/to_integer.rs b/crates/nu-cli/src/commands/str_/to_integer.rs index 2e2a92a48c..0b24e1523c 100644 --- a/crates/nu-cli/src/commands/str_/to_integer.rs +++ b/crates/nu-cli/src/commands/str_/to_integer.rs @@ -65,10 +65,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/trim.rs b/crates/nu-cli/src/commands/str_/trim.rs index 9eac230a3d..a2615e04aa 100644 --- a/crates/nu-cli/src/commands/str_/trim.rs +++ b/crates/nu-cli/src/commands/str_/trim.rs @@ -79,10 +79,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag(), to_trim) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag(), to_trim)?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/commands/str_/upcase.rs b/crates/nu-cli/src/commands/str_/upcase.rs index f13dad5102..c3d40279f6 100644 --- a/crates/nu-cli/src/commands/str_/upcase.rs +++ b/crates/nu-cli/src/commands/str_/upcase.rs @@ -62,10 +62,7 @@ async fn operate( Ok(input .map(move |v| { if column_paths.is_empty() { - match action(&v, v.tag()) { - Ok(out) => ReturnSuccess::value(out), - Err(err) => Err(err), - } + ReturnSuccess::value(action(&v, v.tag())?) } else { let mut ret = v; diff --git a/crates/nu-cli/src/utils.rs b/crates/nu-cli/src/utils.rs index 72db7890d1..f4619a19f4 100644 --- a/crates/nu-cli/src/utils.rs +++ b/crates/nu-cli/src/utils.rs @@ -37,10 +37,7 @@ impl ValueStructure { } let path = if path.starts_with("/") { - match path.strip_prefix("/") { - Ok(p) => p, - Err(_) => path, - } + path.strip_prefix("/").unwrap_or(path) } else { path };