forked from katzen-cafe/iowo
Compare commits
No commits in common. "a3e357a0e7968deedf9fbaccc619eae24c06d470" and "0ebfed66edfec7f7fd810c8f96393588417d99ae" have entirely different histories.
a3e357a0e7
...
0ebfed66ed
8 changed files with 100 additions and 49 deletions
|
@ -2,8 +2,7 @@
|
|||
members = [
|
||||
"crates/app",
|
||||
"crates/eval",
|
||||
"crates/ir",
|
||||
"crates/prowocessing",
|
||||
"crates/ir", "crates/prowocessing",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ enum Commands {
|
|||
},
|
||||
Dev {
|
||||
#[command(subcommand)]
|
||||
command: DevCommands,
|
||||
dev_command: DevCommands,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,7 @@ fn main() {
|
|||
machine.feed(ir);
|
||||
machine.eval_full();
|
||||
}
|
||||
Commands::Dev {
|
||||
command: dev_command,
|
||||
} => dev_command.run(),
|
||||
Commands::Dev { dev_command } => dev_command.run(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,8 +85,7 @@ mod dev {
|
|||
let pipe = PipelineBuilder::new().add(1).stringify().build();
|
||||
println!(
|
||||
"{:?}",
|
||||
pipe.run(vec![&num0.into(), &num1.into()].into())
|
||||
.into_inner()[0]
|
||||
pipe.run(vec![num0.into(), num1.into()].into()).into_inner()[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl Available {
|
|||
#[must_use]
|
||||
pub fn pick(&self) -> Box<dyn Evaluator> {
|
||||
match self {
|
||||
Self::Debug => Box::<kind::debug::Evaluator>::default(),
|
||||
Self::Debug => Box::new(kind::debug::Evaluator::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Definitions of the data transfer and storage types.
|
||||
|
||||
/// Types for element and pipeline IO
|
||||
pub mod io;
|
||||
|
||||
/// Raw data types contained in `io`
|
||||
pub mod raw;
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
//! Types for element and pipeline IO
|
||||
|
||||
use std::{borrow::ToOwned, convert::Into};
|
||||
|
||||
use super::raw::Data;
|
||||
use super::raw::{Data, OwnedData};
|
||||
|
||||
/// Newtype struct with borrowed types for pipeline/element inputs, so that doesn't force a move or clone
|
||||
pub struct Inputs<'a>(pub Vec<&'a Data>);
|
||||
pub struct Inputs<'a>(Vec<Data<'a>>);
|
||||
|
||||
impl<'a> From<Vec<&'a Data>> for Inputs<'a> {
|
||||
fn from(value: Vec<&'a Data>) -> Self {
|
||||
impl<'a> Inputs<'a> {
|
||||
/// get inner value(s)
|
||||
pub(crate) fn inner(&self) -> Vec<Data<'a>> {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Vec<Data<'a>>> for Inputs<'a> {
|
||||
fn from(value: Vec<Data<'a>>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Into<&'a Data>> From<T> for Inputs<'a> {
|
||||
impl<'a, T: Into<Data<'a>>> From<T> for Inputs<'a> {
|
||||
fn from(value: T) -> Self {
|
||||
Self(vec![value.into()])
|
||||
}
|
||||
|
@ -21,31 +24,37 @@ impl<'a, T: Into<&'a Data>> From<T> for Inputs<'a> {
|
|||
|
||||
impl<'a> From<&'a Outputs> for Inputs<'a> {
|
||||
fn from(value: &'a Outputs) -> Self {
|
||||
Self(value.0.iter().map(Into::into).collect())
|
||||
Self(value.0.iter().map(std::convert::Into::into).collect())
|
||||
}
|
||||
}
|
||||
|
||||
/// Used for pipeline/element outputs
|
||||
pub struct Outputs(Vec<Data>);
|
||||
/// Newtype struct around `OwnedData` for pipeline/element outputs
|
||||
pub struct Outputs(Vec<OwnedData>);
|
||||
|
||||
impl Outputs {
|
||||
/// consume self and return inner value(s)
|
||||
pub fn into_inner(self) -> Vec<Data> {
|
||||
pub fn into_inner(self) -> Vec<OwnedData> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl From<Vec<Data>> for Outputs {
|
||||
fn from(value: Vec<Data>) -> Self {
|
||||
impl From<Vec<OwnedData>> for Outputs {
|
||||
fn from(value: Vec<OwnedData>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
impl<T: Into<Data>> From<T> for Outputs {
|
||||
impl<T: Into<OwnedData>> From<T> for Outputs {
|
||||
fn from(value: T) -> Self {
|
||||
Self(vec![value.into()])
|
||||
}
|
||||
}
|
||||
impl From<Inputs<'_>> for Outputs {
|
||||
fn from(value: Inputs) -> Self {
|
||||
Self(value.0.into_iter().map(ToOwned::to_owned).collect())
|
||||
Self(
|
||||
value
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|i: Data<'_>| Data::to_owned_data(&i))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,58 @@
|
|||
//! Dynamic data storage and transfer types for use in [`io`]
|
||||
//! Dynamic data storage and transfer types
|
||||
|
||||
// Dynamic data type
|
||||
/// Owned data type, for use mostly in outputs and storage
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Data {
|
||||
pub enum OwnedData {
|
||||
String(String),
|
||||
Int(i32),
|
||||
}
|
||||
|
||||
impl From<String> for Data {
|
||||
impl From<String> for OwnedData {
|
||||
fn from(value: String) -> Self {
|
||||
Self::String(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for Data {
|
||||
impl From<i32> for OwnedData {
|
||||
fn from(value: i32) -> Self {
|
||||
Self::Int(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Unowned data type, for inputs into runner functions
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Data<'a> {
|
||||
String(&'a str),
|
||||
Int(i32),
|
||||
}
|
||||
|
||||
impl Data<'_> {
|
||||
/// converts itself to `OwnedData`
|
||||
pub fn to_owned_data(&self) -> OwnedData {
|
||||
match self {
|
||||
Data::String(s) => (*s).to_owned().into(),
|
||||
Data::Int(i) => (*i).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Data<'a> {
|
||||
fn from(value: &'a str) -> Self {
|
||||
Self::String(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for Data<'_> {
|
||||
fn from(value: i32) -> Self {
|
||||
Self::Int(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a OwnedData> for Data<'a> {
|
||||
fn from(value: &'a OwnedData) -> Self {
|
||||
match value {
|
||||
OwnedData::String(s) => Data::String(s),
|
||||
OwnedData::Int(i) => Data::Int(*i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,11 @@ pub struct Add(pub i32);
|
|||
impl PipelineElement for Add {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::Int(i0), Data::Int(i1), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::Int(i0), Data::Int(i1), ..] = input.inner()[..] {
|
||||
(i0 + i1).into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,10 +35,11 @@ pub struct Subtract(pub i32);
|
|||
impl PipelineElement for Subtract {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::Int(i0), Data::Int(i1), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::Int(i0), Data::Int(i1), ..] = input.inner()[..] {
|
||||
(i0 + i1).into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,10 +56,11 @@ pub struct Stringify;
|
|||
impl PipelineElement for Stringify {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::Int(int), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::Int(int), ..] = input.inner()[..] {
|
||||
int.to_string().into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,11 @@ pub struct Concatenate(pub String);
|
|||
impl PipelineElement for Concatenate {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::String(s0), Data::String(s1), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::String(s0), Data::String(s1), ..] = input.inner()[..] {
|
||||
format!("{s0}{s1}").into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,10 +33,11 @@ pub struct Upper;
|
|||
impl PipelineElement for Upper {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::String(s), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::String(s), ..] = input.inner()[..] {
|
||||
s.to_uppercase().into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,10 +54,11 @@ pub struct Lower;
|
|||
impl PipelineElement for Lower {
|
||||
fn runner(&self) -> fn(&Inputs) -> Outputs {
|
||||
|input| {
|
||||
let [Data::String(s), ..] = input.0[..] else {
|
||||
panic!("Invalid data passed")
|
||||
};
|
||||
if let [Data::String(s), ..] = input.inner()[..] {
|
||||
s.to_lowercase().into()
|
||||
} else {
|
||||
panic!("Invalid data passed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue