iowo/crates/prowocessing/src/experimental/trait_based/data/io.rs

64 lines
1.4 KiB
Rust

//! Types for element and pipeline IO
use std::convert::Into;
use super::raw::{Data, DataRef};
/// Newtype struct with borrowed types for pipeline/element inputs, so that doesn't force a move or clone
pub struct Inputs<'a>(Vec<DataRef<'a>>);
impl<'a> Inputs<'a> {
/// get inner value(s)
pub(crate) fn inner(&self) -> Vec<DataRef<'a>> {
self.0.clone()
}
}
impl<'a> From<Vec<DataRef<'a>>> for Inputs<'a> {
fn from(value: Vec<DataRef<'a>>) -> Self {
Self(value)
}
}
impl<'a, T: Into<DataRef<'a>>> From<T> for Inputs<'a> {
fn from(value: T) -> Self {
Self(vec![value.into()])
}
}
impl<'a> From<&'a Outputs> for Inputs<'a> {
fn from(value: &'a Outputs) -> Self {
Self(value.0.iter().map(Into::into).collect())
}
}
/// Used for pipeline/element outputs
pub struct Outputs(Vec<Data>);
impl Outputs {
/// consume self and return inner value(s)
pub fn into_inner(self) -> Vec<Data> {
self.0
}
}
impl From<Vec<Data>> for Outputs {
fn from(value: Vec<Data>) -> Self {
Self(value)
}
}
impl<T: Into<Data>> 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(|i: DataRef<'_>| DataRef::to_owned_data(&i))
.collect(),
)
}
}