prowocessing: let-else refatoring as according to review

This commit is contained in:
Schrottkatze 2024-02-23 12:11:35 +01:00
parent b7bc0366c2
commit 619b7acf94
No known key found for this signature in database
2 changed files with 18 additions and 24 deletions

View file

@ -14,11 +14,10 @@ pub struct Add(pub i32);
impl PipelineElement for Add { impl PipelineElement for Add {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] { let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] else {
(i0 + i1).into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
(i0 + i1).into()
} }
} }
@ -35,11 +34,10 @@ pub struct Subtract(pub i32);
impl PipelineElement for Subtract { impl PipelineElement for Subtract {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] { let [DataRef::Int(i0), DataRef::Int(i1), ..] = input.inner()[..] else {
(i0 + i1).into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
(i0 + i1).into()
} }
} }
@ -56,11 +54,10 @@ pub struct Stringify;
impl PipelineElement for Stringify { impl PipelineElement for Stringify {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::Int(int), ..] = input.inner()[..] { let [DataRef::Int(int), ..] = input.inner()[..] else {
int.to_string().into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
int.to_string().into()
} }
} }

View file

@ -12,11 +12,10 @@ pub struct Concatenate(pub String);
impl PipelineElement for Concatenate { impl PipelineElement for Concatenate {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::String(s0), DataRef::String(s1), ..] = input.inner()[..] { let [DataRef::String(s0), DataRef::String(s1), ..] = input.inner()[..] else {
format!("{s0}{s1}").into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
format!("{s0}{s1}").into()
} }
} }
@ -33,11 +32,10 @@ pub struct Upper;
impl PipelineElement for Upper { impl PipelineElement for Upper {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::String(s), ..] = input.inner()[..] { let [DataRef::String(s), ..] = input.inner()[..] else {
s.to_uppercase().into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
s.to_uppercase().into()
} }
} }
@ -54,11 +52,10 @@ pub struct Lower;
impl PipelineElement for Lower { impl PipelineElement for Lower {
fn runner(&self) -> fn(&Inputs) -> Outputs { fn runner(&self) -> fn(&Inputs) -> Outputs {
|input| { |input| {
if let [DataRef::String(s), ..] = input.inner()[..] { let [DataRef::String(s), ..] = input.inner()[..] else {
s.to_lowercase().into()
} else {
panic!("Invalid data passed") panic!("Invalid data passed")
} };
s.to_lowercase().into()
} }
} }