Flecs-Rust icon indicating copy to clipboard operation
Flecs-Rust copied to clipboard

Safety follow up work

Open Indra-db opened this issue 11 months ago • 0 comments

from PR #238

Follow up work:

Right now queries can have signatures like &mut Foo, &Foo or &mut Foo, &mut Foo. This becomes a problem with multi source queries & self multiplying queries like &mut Foo($x), &mut Foo($y) that might have 1 variable unset. To address this a new feature & breaking changes have to be added that prevents queries, systems, observers, etc from having multiple of the same component in their signature if any one of them is a writer. Then we can do something like force the user to go through iter. Example pseudo code:

world.query::<()>()
    .with::<&mut Foo>().set_src_name("x")
    .with::<&mut Foo>().set_src_name("y")
    .each_iter(|iter, _, _| {
        // Will give `Ok` for the first instance of an entity & `Err` for any instance after
        let [Ok(a), Ok(b)] = iter.get::<&mut Foo>(["x", "y"]) else {
            return
        };
    });

Indra-db avatar Feb 28 '25 23:02 Indra-db