Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. trait Surface: 'static {}
  2.  
  3. struct Manager {
  4. storage: Vec<Box<Surface>>,
  5. }
  6.  
  7. impl Manager {
  8. fn add(&mut self, surface: impl Surface) {
  9. self.storage.push(Box::new(surface));
  10. }
  11. }
  12.  
  13. struct SomeOtherStruct {}
  14.  
  15. struct Obj<'a> {
  16. data: &'a mut SomeOtherStruct,
  17. }
  18.  
  19. impl<'a> Obj<'a> {
  20. fn new(some_struct: &'a mut SomeOtherStruct) -> Self {
  21. Obj {
  22. data: some_struct
  23. }
  24. }
  25. }
  26.  
  27. impl<'a> Surface for Obj<'a> where 'a: 'static {}
  28.  
  29. fn main() {
  30. let mut some_struct = SomeOtherStruct{};
  31. let mut manager = Manager { storage: Vec::new() };
  32.  
  33. let obj = Obj::new(&mut some_struct);
  34. manager.add(obj);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement