Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct Foo {
  3. id: i32,
  4. }
  5.  
  6. #[derive(Debug)]
  7. struct Bar;
  8.  
  9. #[derive(Debug, Default)]
  10. struct World {
  11. foos: Foos,
  12. bars: Bars,
  13. }
  14.  
  15. #[derive(Debug, Default)]
  16. struct Foos(Vec<Foo>);
  17.  
  18. impl Foos {
  19. fn get_mut(&mut self) -> &mut [Foo] {
  20. &mut self.0
  21. }
  22. }
  23.  
  24. #[derive(Debug, Default)]
  25. struct Bars(Vec<Bar>);
  26.  
  27. impl Bars {
  28. fn get(&self, foo: &Foo) -> &Bar {
  29. &self.0[foo.id as usize]
  30. }
  31. }
  32.  
  33. impl World {
  34. pub fn create() -> Self {
  35. Self::default()
  36. }
  37.  
  38. pub fn update(&mut self) {
  39. for foo in self.foos.get_mut() {
  40. let _bar = self.bars.get(foo);
  41. }
  42. }
  43. }
  44.  
  45. fn main() {
  46. let mut world = World::create();
  47. world.update();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement