Support for get_many and get_many_mut functions for Assets<T>

Part of #16244
This commit is contained in:
Rajveer 2024-11-10 23:45:59 +05:30
parent e155fe1d86
commit b141be92e0

View File

@ -215,6 +215,19 @@ impl<A: Asset> DenseAssetStorage<A> {
}
}
pub(crate) fn get_many<const N: usize>(&self, indices: [AssetIndex; N]) -> [Option<&A>; N] {
indices.map(|index| match self.storage.get(index.index as usize)? {
Entry::None => None,
Entry::Some { value, generation } => {
if *generation == index.generation {
value.as_ref()
} else {
None
}
}
})
}
pub(crate) fn get_mut(&mut self, index: AssetIndex) -> Option<&mut A> {
let entry = self.storage.get_mut(index.index as usize)?;
match entry {
@ -229,6 +242,13 @@ impl<A: Asset> DenseAssetStorage<A> {
}
}
pub(crate) fn get_many_mut<const N: usize>(
&mut self,
indices: [AssetIndex; N],
) -> [Option<&mut A>; N] {
todo!()
}
pub(crate) fn flush(&mut self) {
// NOTE: this assumes the allocator index is monotonically increasing.
let new_len = self