From 619b7acf94e26efd2c3a0df935c66e3dc4ec8e92 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Fri, 23 Feb 2024 12:11:35 +0100 Subject: [PATCH] prowocessing: let-else refatoring as according to review --- .../src/experimental/trait_based/ops/num.rs | 21 ++++++++----------- .../src/experimental/trait_based/ops/str.rs | 21 ++++++++----------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/crates/prowocessing/src/experimental/trait_based/ops/num.rs b/crates/prowocessing/src/experimental/trait_based/ops/num.rs index 09b4372..a6ac18c 100644 --- a/crates/prowocessing/src/experimental/trait_based/ops/num.rs +++ b/crates/prowocessing/src/experimental/trait_based/ops/num.rs @@ -14,11 +14,10 @@ pub struct Add(pub i32); impl PipelineElement for Add { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] { - (i0 + i1).into() - } else { + let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + (i0 + i1).into() } } @@ -35,11 +34,10 @@ pub struct Subtract(pub i32); impl PipelineElement for Subtract { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] { - (i0 + i1).into() - } else { + let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + (i0 + i1).into() } } @@ -56,11 +54,10 @@ pub struct Stringify; impl PipelineElement for Stringify { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::Int(int), ..] = input.inner()[..] { - int.to_string().into() - } else { + let [DataRef::Int(int), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + int.to_string().into() } } diff --git a/crates/prowocessing/src/experimental/trait_based/ops/str.rs b/crates/prowocessing/src/experimental/trait_based/ops/str.rs index dc0d99d..49ce606 100644 --- a/crates/prowocessing/src/experimental/trait_based/ops/str.rs +++ b/crates/prowocessing/src/experimental/trait_based/ops/str.rs @@ -12,11 +12,10 @@ pub struct Concatenate(pub String); impl PipelineElement for Concatenate { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::String(s0), DataRef::String(s1), ..] = input.inner()[..] { - format!("{s0}{s1}").into() - } else { + let [DataRef::String(s0), DataRef::String(s1), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + format!("{s0}{s1}").into() } } @@ -33,11 +32,10 @@ pub struct Upper; impl PipelineElement for Upper { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::String(s), ..] = input.inner()[..] { - s.to_uppercase().into() - } else { + let [DataRef::String(s), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + s.to_uppercase().into() } } @@ -54,11 +52,10 @@ pub struct Lower; impl PipelineElement for Lower { fn runner(&self) -> fn(&Inputs) -> Outputs { |input| { - if let [DataRef::String(s), ..] = input.inner()[..] { - s.to_lowercase().into() - } else { + let [DataRef::String(s), ..] = input.inner()[..] else { panic!("Invalid data passed") - } + }; + s.to_lowercase().into() } }