use std::marker::PhantomData;
pub trait Transcoder: Send {
type Input: Send + 'static;
type Output: Send + 'static;
fn prologue(&mut self) -> Vec<Self::Output> {
Vec::new()
}
fn transcode(&mut self, item: &Self::Input) -> Vec<Self::Output>;
fn epilogue(&mut self) -> Vec<Self::Output> {
Vec::new()
}
}
pub struct Identity<T>(PhantomData<T>);
impl<T> Default for Identity<T> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<T: Clone + Send + 'static> Transcoder for Identity<T> {
type Input = T;
type Output = T;
fn transcode(&mut self, item: &Self::Input) -> Vec<Self::Output> {
vec![item.clone()]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_passthrough() {
let mut t = Identity::<u32>::default();
assert_eq!(t.transcode(&42), vec![42]);
}
}