WIP: image processing library (or libraries?) #12

Draft
schrottkatze wants to merge 15 commits from schrottkatze/iowo:proc-libs into main
4 changed files with 21 additions and 33 deletions
Showing only changes of commit 4bc84451e0 - Show all commits

View file

@ -5,6 +5,7 @@
//! - [Builder pattern](https://rust-unofficial.github.io/patterns/patterns/creational/builder.html) //! - [Builder pattern](https://rust-unofficial.github.io/patterns/patterns/creational/builder.html)
pub mod data; pub mod data;
#[macro_use]
pub mod element; pub mod element;
pub mod ops; pub mod ops;
pub mod pipeline; pub mod pipeline;

View file

@ -1,5 +1,7 @@
//! The trait and type representations //! The trait and type representations
use std::any::TypeId;
use crate::experimental::trait_based::data::io::Inputs; use crate::experimental::trait_based::data::io::Inputs;
use super::data::io::Outputs; use super::data::io::Outputs;
@ -13,13 +15,15 @@ pub(crate) trait PipelineElement {
/// Type signature for an element used for static checking /// Type signature for an element used for static checking
pub(crate) struct ElementSignature { pub(crate) struct ElementSignature {
pub inputs: Vec<DataType>, pub inputs: Vec<TypeId>,
pub outputs: Vec<DataType>, pub outputs: Vec<TypeId>,
} }
/// Data type enum macro_rules! signature {
#[derive(Clone, Copy, PartialEq, Eq, Debug)] ($($inputs:ty),+ => $($outputs:ty),+) => (
pub enum DataType { ElementSignature {
String, inputs: vec![$(std::any::TypeId::of::<$inputs>(), )+],
Int, outputs: vec![$(std::any::TypeId::of::<$outputs>(), )+]
}
)
} }

View file

@ -1,12 +1,13 @@
//! Operations on numeric data //! Operations on numeric data
use core::panic; use core::panic;
use std::any::TypeId;
use crate::experimental::trait_based::{ use crate::experimental::trait_based::{
data::{ data::{
io::{Inputs, Outputs}, io::{Inputs, Outputs},
raw::Data, raw::Data,
}, },
element::{DataType, ElementSignature, PipelineElement}, element::{ElementSignature, PipelineElement},
}; };
/// Addition /// Addition
@ -22,10 +23,7 @@ impl PipelineElement for Add {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(i32, i32 => i32)
inputs: vec![DataType::Int, DataType::Int],
outputs: vec![DataType::Int],
}
} }
} }
@ -42,10 +40,7 @@ impl PipelineElement for Subtract {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(i32, i32 => i32)
inputs: vec![DataType::Int, DataType::Int],
outputs: vec![DataType::Int],
}
} }
} }
@ -62,9 +57,6 @@ impl PipelineElement for Stringify {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(i32 => String)
inputs: vec![DataType::Int],
outputs: vec![DataType::String],
}
} }
} }

View file

@ -4,7 +4,7 @@ use crate::experimental::trait_based::{
io::{Inputs, Outputs}, io::{Inputs, Outputs},
raw::Data, raw::Data,
}, },
element::{DataType, ElementSignature, PipelineElement}, element::{ElementSignature, PipelineElement},
}; };
/// Concatenate the inputs /// Concatenate the inputs
@ -20,10 +20,7 @@ impl PipelineElement for Concatenate {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(String, String => String)
inputs: vec![DataType::String, DataType::String],
outputs: vec![DataType::String],
}
} }
} }
@ -40,10 +37,7 @@ impl PipelineElement for Upper {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(String => String)
inputs: vec![DataType::String],
outputs: vec![DataType::String],
}
} }
} }
@ -60,9 +54,6 @@ impl PipelineElement for Lower {
} }
fn signature(&self) -> ElementSignature { fn signature(&self) -> ElementSignature {
ElementSignature { signature!(String => String)
inputs: vec![DataType::String],
outputs: vec![DataType::String],
}
} }
} }