Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct Foo {
- id: i32,
- }
- #[derive(Debug)]
- struct Bar;
- #[derive(Debug, Default)]
- struct World {
- foos: Foos,
- bars: Bars,
- }
- #[derive(Debug, Default)]
- struct Foos(Vec<Foo>);
- impl Foos {
- fn get_mut(&mut self) -> &mut [Foo] {
- &mut self.0
- }
- }
- #[derive(Debug, Default)]
- struct Bars(Vec<Bar>);
- impl Bars {
- fn get(&self, foo: &Foo) -> &Bar {
- &self.0[foo.id as usize]
- }
- }
- impl World {
- pub fn create() -> Self {
- Self::default()
- }
- pub fn update(&mut self) {
- for foo in self.foos.get_mut() {
- let _bar = self.bars.get(foo);
- }
- }
- }
- fn main() {
- let mut world = World::create();
- world.update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement