use subenum::subenum;
trait Processor {
type Input;
type Output;
}
struct Audio;
impl Processor for Audio {
type Input = Vec<u8>;
type Output = Vec<f32>;
}
struct Video;
impl Processor for Video {
type Input = Vec<u32>;
type Output = Vec<u8>;
}
#[subenum(InputOnly, OutputOnly)]
enum Pipeline<P>
where
P: Processor,
P::Input: PartialEq + std::fmt::Debug,
P::Output: Clone,
{
#[subenum(InputOnly)]
Source(P::Input),
#[subenum(OutputOnly)]
Sink(P::Output),
}
#[test]
fn test_associated_type_usage() {
let src_audio: InputOnly<Audio> = InputOnly::Source(vec![1, 2, 3]);
let src_video: InputOnly<Video> = InputOnly::Source(vec![10, 20]);
match src_audio {
InputOnly::Source(bytes) => assert_eq!(bytes.len(), 3),
}
match src_video {
InputOnly::Source(bytes) => assert_eq!(bytes.len(), 2),
}
let sink: OutputOnly<Audio> = OutputOnly::Sink(vec![0.0, 1.0]);
match sink {
OutputOnly::Sink(floats) => assert_eq!(floats.len(), 2),
}
}