SHARE
TWEET

Untitled

a guest Aug 21st, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::marker::PhantomData;
  2. use std::fmt::Error;
  3.  
  4. trait Sample {}
  5. impl Sample for u8 {}
  6. impl Sample for u16 {}
  7. impl Sample for u32 {}
  8.  
  9. struct Parameters<S:?Sized> { sample_format: std::marker::PhantomData<S>, }
  10.  
  11. pub type InputSource<T> where T : ?Sized + Sample + 'static = Parameters<T>;
  12. pub type OutputSource<T> where T : ?Sized + Sample + 'static = Parameters<T>;
  13.  
  14. pub struct InputFlow<T> where T : ?Sized + Sample + 'static { pub source: InputSource<T> }
  15. pub struct OutputFlow<T> where T : ?Sized + Sample + 'static { pub source: OutputSource<T> }
  16. pub trait AudioFlow<T> where T : ?Sized + Sample + 'static {}
  17.  
  18. impl <T> AudioFlow<T> for InputFlow<T> where T : ?Sized + Sample + 'static {}
  19. impl <T> AudioFlow<T> for OutputFlow<T> where T : ?Sized + Sample + 'static {}
  20.  
  21. pub enum AudioType { Input, Output }
  22. pub fn flow<T>(ty: AudioType) -> Result<Box<dyn AudioFlow<T>>, Error>
  23.     where T : ?Sized + Sample + 'static {
  24.  
  25.     match ty {
  26.         AudioType::Input => flow_input::<T>(),
  27.         AudioType::Output => flow_output::<T>()
  28.     }
  29. }
  30.  
  31. pub fn flow_input<T>() -> Result<Box<InputFlow<T>>, Error>
  32.     where T : ?Sized + Sample + 'static {
  33.  
  34.     let source = Parameters { sample_format: std::marker::PhantomData };
  35.     return Ok(Box::new(InputFlow { source }))
  36. }
  37.  
  38. pub fn flow_output<T>() -> Result<Box<OutputFlow<T>>, Error>
  39.     where T : ?Sized + Sample + 'static {
  40.  
  41.     let source = Parameters { sample_format: std::marker::PhantomData };
  42.     return Ok(Box::new(OutputFlow { source}))
  43. }
  44.  
  45.  
  46. fn main() {
  47.     let a = flow::<u32>(AudioType::Input);
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top