[Merged by Bors] - exact sized event iterators#3863
[Merged by Bors] - exact sized event iterators#3863mockersf wants to merge 3 commits intobevyengine:mainfrom
Conversation
86540de to
ddd900c
Compare
alice-i-cecile
left a comment
There was a problem hiding this comment.
Yes please to an event trait. IMO we may want to remove the blanket impl later, but that can be done when we need it.
|
Related to #2073, which also introduces and uses an |
|
@alice-i-cecile why the |
|
The |
|
Nop, everything that impl |
|
So, consider this extension method on pub fn send_event<E: Resource>(&mut self, event: E) {
let mut events: Mut<Events<E>> = self.get_resource_mut()
.expect("The specified event resource was not found in the world. Did you forget to call `app.add_event::<E>()`?");
events.send(event);
}This can be written entirely in end user code, and will cease to compile after this change. Every possible use of it will still be valid, but the type signature itself is now wrong because of the bound here: bevy/crates/bevy_ecs/src/event.rs Line 359 in ddd900c I 100% think this is the right call, but the change is technically breaking 🤷🏽 EDIT: no, this will still compile, because Rust can infer that all |
ddd900c to
53fb21a
Compare
Co-Authored-By: Alice Cecile <alice.i.cecile@gmail.com>
53fb21a to
304b865
Compare
|
bors r+ |
# Objective - Remove `Resource` binding on events, introduce a new `Event` trait - Ensure event iterators are `ExactSizeIterator` ## Solution - Builds on #2382 and #2969 ## Changelog - Events<T>, EventWriter<T>, EventReader<T> and so on now require that the underlying type is Event, rather than Resource. Both of these are trivial supertraits of Send + Sync + 'static with universal blanket implementations: this change is currently purely cosmetic. - Event reader iterators now implement ExactSizeIterator
# Objective - Remove `Resource` binding on events, introduce a new `Event` trait - Ensure event iterators are `ExactSizeIterator` ## Solution - Builds on bevyengine#2382 and bevyengine#2969 ## Changelog - Events<T>, EventWriter<T>, EventReader<T> and so on now require that the underlying type is Event, rather than Resource. Both of these are trivial supertraits of Send + Sync + 'static with universal blanket implementations: this change is currently purely cosmetic. - Event reader iterators now implement ExactSizeIterator
# Objective - Remove `Resource` binding on events, introduce a new `Event` trait - Ensure event iterators are `ExactSizeIterator` ## Solution - Builds on bevyengine#2382 and bevyengine#2969 ## Changelog - Events<T>, EventWriter<T>, EventReader<T> and so on now require that the underlying type is Event, rather than Resource. Both of these are trivial supertraits of Send + Sync + 'static with universal blanket implementations: this change is currently purely cosmetic. - Event reader iterators now implement ExactSizeIterator
# Objective - Remove `Resource` binding on events, introduce a new `Event` trait - Ensure event iterators are `ExactSizeIterator` ## Solution - Builds on bevyengine#2382 and bevyengine#2969 ## Changelog - Events<T>, EventWriter<T>, EventReader<T> and so on now require that the underlying type is Event, rather than Resource. Both of these are trivial supertraits of Send + Sync + 'static with universal blanket implementations: this change is currently purely cosmetic. - Event reader iterators now implement ExactSizeIterator
Objective
Resourcebinding on events, introduce a newEventtraitExactSizeIteratorSolution
Changelog