From 3e33964aa800376e4c60e71c735b8eef7788c4e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 16 Nov 2024 18:35:08 +0100 Subject: feat(ecs): check comp metadata list before creating archetype ID --- ecs/src/archetype.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'ecs/src/archetype.rs') diff --git a/ecs/src/archetype.rs b/ecs/src/archetype.rs index 5c104b7..d2ee36a 100644 --- a/ecs/src/archetype.rs +++ b/ecs/src/archetype.rs @@ -16,12 +16,25 @@ pub struct Id impl Id { pub fn from_components_metadata( - components_metadata: impl IntoIterator, + components_metadata: &impl AsRef<[ComponentMetadata]>, ) -> Self { + debug_assert!( + components_metadata.as_ref().len() > 0, + "Cannot create a archetype ID from a empty component metadata list" + ); + + debug_assert!( + components_metadata + .as_ref() + .is_sorted_by_key(|comp_metadata| comp_metadata.id), + "Cannot create archetype ID from a unsorted component metadata list" + ); + Self::new( components_metadata - .into_iter() + .as_ref() + .iter() .filter_map(|component_metadata| { if component_metadata.is_optional == ComponentIsOptional::Yes { return None; -- cgit v1.2.3-18-g5258