Skip to content
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

More safely support untyped Observer events #17509

Open
ItsDoot opened this issue Jan 23, 2025 · 0 comments
Open

More safely support untyped Observer events #17509

ItsDoot opened this issue Jan 23, 2025 · 0 comments
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@ItsDoot
Copy link
Contributor

ItsDoot commented Jan 23, 2025

What problem does this solve or what need does it fill?

We don't currently support specifying an untyped event as the event type in an Observer Trigger. Our "support" for it currently involves specifying some rust type as the event type and providing a Trigger::event_ptr function which returns a Ptr, also not providing a version that returns PtrMut.
Doing it this way can cause accidental UB on the user side very easily if they don't specify a type compatible with all of the event types.

What solution would you like?

We should directly support specifying untyped events as the event type in the Trigger like so:

fn my_observer(trigger: Trigger<UntypedEvent>, /* ... */) {
    /* ... */
}

And then we would have a type function that maps UntypedEvent into a Ptr for Trigger::event() and a PtrMut for Trigger::event_mut().

Additional context

Originally attempted in #14674 but that PR languished due to a too large of a scope.

@ItsDoot ItsDoot added A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

1 participant