Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for get_many and get_many_mut functions for Assets<T> #16334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading