Skip to content

Commit 42dad93

Browse files
Fix lifetime errors in drain methods
1 parent 620bbbc commit 42dad93

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

crates/bevy_ecs/src/event.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,15 @@ pub struct EventConsumer<'a, T: Component> {
358358

359359
impl<'a, T: Component> EventConsumer<'a, T> {
360360
/// Drains all available events this EventConsumer has access to into an iterator
361-
pub fn drain(self) -> impl DoubleEndedIterator<Item = T> {
362-
self.events.drain()
361+
pub fn drain(self) -> impl DoubleEndedIterator<Item = T> + 'a {
362+
// into_inner is needed to ensure the lifetime is not bound to the implicit .deref_mut() call
363+
self.events.into_inner().drain()
363364
}
364365

365366
/// Drains all available events this EventConsumer has access to into an iterator and returns the id
366-
pub fn drain_with_id(self) -> impl DoubleEndedIterator<Item = (T, EventId<T>)> {
367-
self.events.drain_with_id()
367+
pub fn drain_with_id(self) -> impl DoubleEndedIterator<Item = (T, EventId<T>)> + 'a {
368+
// into_inner is needed to ensure the lifetime is not bound to the implicit .deref_mut() call
369+
self.events.into_inner().drain_with_id()
368370
}
369371
}
370372

0 commit comments

Comments
 (0)