From 7f3072ed7e016dff359439d7580403e36ad6b325 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 15 Oct 2025 18:40:19 +0200 Subject: feat(ecs): add EventMatch convenience fns for component events --- ecs/src/system/observer.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'ecs/src/system') diff --git a/ecs/src/system/observer.rs b/ecs/src/system/observer.rs index b7d84be..236420c 100644 --- a/ecs/src/system/observer.rs +++ b/ecs/src/system/observer.rs @@ -82,18 +82,19 @@ impl<'world, ObservedT: Observed> Observe<'world, ObservedT> impl Observe<'_, ObservedT> { #[must_use] - pub fn iter(&self) -> ObserveIter<'_> + pub fn iter(&self) -> ObserveIter<'_, ObservedT> { ObserveIter { world: self.world, inner: self.emitted_event.match_ids.iter(), + _pd: PhantomData, } } } impl<'a, ObservedT: Observed> IntoIterator for &'a Observe<'_, ObservedT> { - type IntoIter = ObserveIter<'a>; + type IntoIter = ObserveIter<'a, ObservedT>; type Item = ::Item; fn into_iter(self) -> Self::IntoIter @@ -102,33 +103,39 @@ impl<'a, ObservedT: Observed> IntoIterator for &'a Observe<'_, ObservedT> } } -pub struct ObserveIter<'observe> +pub struct ObserveIter<'observe, ObservedT: Observed> { world: &'observe World, inner: SliceIter<'observe, Uid>, + _pd: PhantomData, } -impl<'observe> Iterator for ObserveIter<'observe> +impl<'observe, ObservedT: Observed> Iterator for ObserveIter<'observe, ObservedT> { - type Item = EventMatch<'observe>; + type Item = EventMatch<'observe, ObservedT>; fn next(&mut self) -> Option { let match_id = *self.inner.next()?; - Some(EventMatch { world: self.world, id: match_id }) + Some(EventMatch { + world: self.world, + id: match_id, + _pd: PhantomData, + }) } } /// A event match. #[derive(Debug)] -pub struct EventMatch<'world> +pub struct EventMatch<'world, ObservedT: Observed> { world: &'world World, id: Uid, + _pd: PhantomData, } -impl<'world> EventMatch<'world> +impl<'world, ObservedT: Observed> EventMatch<'world, ObservedT> { #[must_use] pub fn id(&self) -> Uid -- cgit v1.2.3-18-g5258