rj00a / evenio

An event-driven Entity Component System
MIT License
137 stars 14 forks source link

feat: SyncUnsafeCell query #53

Closed andrewgazelka closed 6 months ago

andrewgazelka commented 6 months ago

This currently requires nightly. Maybe we could make our own SyncUnsafeCell?

anyway, this type of thing can be useful for when I want to use Fetcher inside of a ParallelIterator and I know I have enforced invariants such that I will never be mutably accessing the same element from two places at once.

This is the big use case I can think of and UnsafeCell will probs not be happy since it is not Sync but SyncUnsafeCell would be.

rj00a commented 6 months ago

I would prefer a Fetcher::get_unchecked method instead. It can be defined the same as Fetcher::get but without the Q: ReadOnlyQuery bound.

    #[inline]
    pub unsafe fn get_unchecked(&self, entity: EntityId) -> Result<Q::Item<'_>, GetError> {
        self.state.get_unchecked(self.world.entities(), entity)
    }

See also: https://docs.rs/bevy_ecs/latest/bevy_ecs/system/struct.Query.html#method.get_unchecked

andrewgazelka commented 6 months ago

I agree I like get unchecked better just wasn’t sure how to implement