Guest User

Untitled

a guest
Aug 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. trait Volume {}
  2.  
  3. struct RawChunk; impl Volume for RawChunk {}
  4. struct RleChunk; impl Volume for RleChunk {}
  5. struct FileChunk; impl Volume for FileChunk {}
  6.  
  7. struct Container {
  8. raw: Option<RawChunk>,
  9. rle: Option<RleChunk>,
  10. file: Option<FileChunk>,
  11. }
  12.  
  13. impl Container {
  14. fn get<'a>(&'a self, variant: i32) -> Option<&'a impl Volume> {
  15. match variant {
  16. 0 => self.raw.as_ref(),
  17. 1 => self.raw.as_ref(),
  18. 2 => self.raw.as_ref(),
  19. _ => panic!(),
  20. }
  21. }
  22. }
  23.  
  24. fn main() {
  25. println!("Hello, world!");
  26.  
  27. let container = Container {
  28. raw: Some(RawChunk),
  29. rle: Some(RleChunk),
  30. file: Some(FileChunk),
  31. };
  32.  
  33. let rle = container.get(0);
  34. }
Add Comment
Please, Sign In to add comment