From b141be92e086c615a722800027fa04ff25159a63 Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer@icloud.com>
Date: Sun, 10 Nov 2024 23:45:59 +0530
Subject: [PATCH] Support for `get_many` and `get_many_mut` functions for
 `Assets<T>`

Part of #16244
---
 crates/bevy_asset/src/assets.rs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs
index 5f4a053846599..6f30e3428fa99 100644
--- a/crates/bevy_asset/src/assets.rs
+++ b/crates/bevy_asset/src/assets.rs
@@ -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