-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - exact sized event iterators #3863
Conversation
86540de
to
ddd900c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Resource
binding on events, introduce a newEvent
traitExactSizeIterator
Solution
Changelog