From 42b928b90e55a242747682bed327e0ae3a9aa94e Mon Sep 17 00:00:00 2001 From: AlephCubed <76791009+AlephCubed@users.noreply.github.com> Date: Mon, 20 Jan 2025 18:19:02 -0800 Subject: [PATCH] Added helper methods to `Bundles`. (#17464) Added `len`, `is_empty`, and `iter` methods to `Bundles`. Separated out from #17331. --------- Co-authored-by: shuo --- crates/bevy_ecs/src/bundle.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index d18d6bdd2a68a..fb7d61cbb959d 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -1473,6 +1473,21 @@ pub struct Bundles { } impl Bundles { + /// The total number of [`Bundle`] registered in [`Storages`]. + pub fn len(&self) -> usize { + self.bundle_infos.len() + } + + /// Returns true if no [`Bundle`] registered in [`Storages`]. + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + /// Iterate over [`BundleInfo`]. + pub fn iter(&self) -> impl Iterator { + self.bundle_infos.iter() + } + /// Gets the metadata associated with a specific type of bundle. /// Returns `None` if the bundle is not registered with the world. #[inline]