forked from katzen-cafe/iowo
prowocessing: refactor trait based experiment to individual files
This commit is contained in:
parent
26996fbd00
commit
dddbcccf72
10 changed files with 362 additions and 341 deletions
69
crates/prowocessing/src/experimental/trait_based/ops/num.rs
Normal file
69
crates/prowocessing/src/experimental/trait_based/ops/num.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use core::panic;
|
||||
|
||||
use crate::experimental::trait_based::{
|
||||
data::{
|
||||
io::{Inputs, Outputs},
|
||||
raw::Data,
|
||||
},
|
||||
element::{DataType, ElementIo, PipelineElement},
|
||||
};
|
||||
|
||||
pub struct Add(pub i32);
|
||||
impl PipelineElement for Add {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
if let [Data::Int(i0), Data::Int(i1), ..] = input.inner()[..] {
|
||||
(i0 + i1).into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn signature(&self) -> ElementIo {
|
||||
ElementIo {
|
||||
inputs: vec![DataType::Int, DataType::Int],
|
||||
outputs: vec![DataType::Int],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Subtract(pub i32);
|
||||
impl PipelineElement for Subtract {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
if let [Data::Int(i0), Data::Int(i1), ..] = input.inner()[..] {
|
||||
(i0 + i1).into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn signature(&self) -> ElementIo {
|
||||
ElementIo {
|
||||
inputs: vec![DataType::Int, DataType::Int],
|
||||
outputs: vec![DataType::Int],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Stringify;
|
||||
impl PipelineElement for Stringify {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
if let [Data::Int(int), ..] = input.inner()[..] {
|
||||
int.to_string().into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn signature(&self) -> ElementIo {
|
||||
ElementIo {
|
||||
inputs: vec![DataType::Int],
|
||||
outputs: vec![DataType::String],
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue