Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- use std::fmt::Error;
- trait Sample {}
- impl Sample for u8 {}
- impl Sample for u16 {}
- impl Sample for u32 {}
- struct Parameters<S:?Sized> { sample_format: std::marker::PhantomData<S>, }
- pub type InputSource<T> where T : ?Sized + Sample + 'static = Parameters<T>;
- pub type OutputSource<T> where T : ?Sized + Sample + 'static = Parameters<T>;
- pub struct InputFlow<T> where T : ?Sized + Sample + 'static { pub source: InputSource<T> }
- pub struct OutputFlow<T> where T : ?Sized + Sample + 'static { pub source: OutputSource<T> }
- pub trait AudioFlow<T> where T : ?Sized + Sample + 'static {}
- impl <T> AudioFlow<T> for InputFlow<T> where T : ?Sized + Sample + 'static {}
- impl <T> AudioFlow<T> for OutputFlow<T> where T : ?Sized + Sample + 'static {}
- pub enum AudioType { Input, Output }
- pub fn flow<T>(ty: AudioType) -> Result<Box<dyn AudioFlow<T>>, Error>
- where T : ?Sized + Sample + 'static {
- match ty {
- AudioType::Input => flow_input::<T>(),
- AudioType::Output => flow_output::<T>()
- }
- }
- pub fn flow_input<T>() -> Result<Box<InputFlow<T>>, Error>
- where T : ?Sized + Sample + 'static {
- let source = Parameters { sample_format: std::marker::PhantomData };
- return Ok(Box::new(InputFlow { source }))
- }
- pub fn flow_output<T>() -> Result<Box<OutputFlow<T>>, Error>
- where T : ?Sized + Sample + 'static {
- let source = Parameters { sample_format: std::marker::PhantomData };
- return Ok(Box::new(OutputFlow { source}))
- }
- fn main() {
- let a = flow::<u32>(AudioType::Input);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement