macro_rules! get_components_mut {
    ($engine:expr, $entity:expr, $($component:ty),*) => { ... };
}
Expand description

This macro is used to muttably borrow a variable ammount of components from an entity

It returns a tuple of references to the components

use ABC_ECS::{get_components_mut, GameEngine, Component};

struct Position {
    x: f32,
    y: f32,
}

impl Component for Position {}

struct Velocity {
    x: f32,
    y: f32,
}

impl Component for Velocity {}


fn main() {
    let mut engine = GameEngine::new();
    let entities_and_components = &mut engine.entities_and_components;

    let entity = entities_and_components.add_entity();

    entities_and_components.add_component_to(entity, Position { x: 0.0, y: 0.0 });
    entities_and_components.add_component_to(entity, Velocity { x: 1.0, y: 1.0 });

    let (position, velocity) = get_components_mut!(engine.entities_and_components, entity, Position, Velocity);

    position.x += velocity.x;
    position.y += velocity.y;

    println!("Position: {}, {}", position.x, position.y);
}

WARNING: This macro is not safe to use if you are borrowing the same component mutably more than once

It will panic if you do this in a single call to the macro, but it will not panic if you do it in seperate calls