Skip to content

Commit

Permalink
Support for get_many and get_many_mut functions for Assets<T>
Browse files Browse the repository at this point in the history
Part of #16244
  • Loading branch information
Rajveer100 committed Nov 10, 2024
1 parent 619c5e3 commit ca2f8b2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit ca2f8b2

Please sign in to comment.