IndexStorage

Trait IndexStorage 

Source
pub trait IndexStorage<I: IndexInfo>: Resource + Default {
    type RefreshData<'w, 's>: SystemParam;

    // Required methods
    fn lookup<'w, 's>(
        &mut self,
        val: &I::Value,
        data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>,
    ) -> impl Iterator<Item = Entity>;
    fn refresh<'w, 's>(
        &mut self,
        data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>,
    );
    fn force_refresh<'w, 's>(
        &mut self,
        data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>,
    );
    fn insertion_observer() -> Option<Observer>;
    fn removal_observer() -> Option<Observer>;
}
Expand description

Defines the internal storage for an index, which is stored as a Resource.

You should not need this for normal use beyond including the Storage type in your IndexInfo implementations, but you can use this to customize the storage of your index’s data if necessary

This crate provides the following storage implementations:

HashmapStorage, NoStorage

Required Associated Types§

Source

type RefreshData<'w, 's>: SystemParam

SystemParam that is fetched alongside this storage Resource when an Index is included in a system.

It is passed in when querying or updating the index.

Required Methods§

Source

fn lookup<'w, 's>( &mut self, val: &I::Value, data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>, ) -> impl Iterator<Item = Entity>

Get all of the entities with relevant components that evaluate to the given value using I::value.

Source

fn refresh<'w, 's>( &mut self, data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>, )

Refresh this storage with the latest state from the world if it hasn’t already been refreshed this Tick.

Note: 1 Tick = 1 system, not 1 frame.

Source

fn force_refresh<'w, 's>( &mut self, data: &mut StaticSystemParam<'_, '_, Self::RefreshData<'w, 's>>, )

Unconditionally refresh this storage with the latest state from the world.

Source

fn insertion_observer() -> Option<Observer>

Observer to be run whenever a component tracked by this Index is inserted.

No observer will be registered if this returns None.

Source

fn removal_observer() -> Option<Observer>

Observer to be run whenever a component tracked by this Index is removed.

No observer will be registered if this returns None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I: IndexInfo> IndexStorage<I> for HashmapStorage<I>

Source§

type RefreshData<'w, 's> = HashmapStorageRefreshData<'w, 's, I>

Source§

impl<I: IndexInfo> IndexStorage<I> for NoStorage<I>

Source§

type RefreshData<'w, 's> = Query<'w, 's, (Entity, &'static <I as IndexInfo>::Component)>