forked from katzen-cafe/iowo
70 lines
1.7 KiB
Rust
70 lines
1.7 KiB
Rust
|
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],
|
||
|
}
|
||
|
}
|
||
|
}
|