More safely support untyped `Observer` events
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## 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:
```rust
fn my_observer(trigger: Trigger, /* ... */) {
/* ... */
}
```
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.
Contributor guide
Assessment
This issue has not been assessed yet.