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

api: add ApplicationHandler::as_any #3851

Closed
wants to merge 1 commit into from
Closed

Conversation

kchibisov
Copy link
Member

This could be used to subscribe for custom events.

This could be used to subscribe for custom events.
@kchibisov
Copy link
Member Author

Example on how to use it #3852

Comment on lines +331 to +337
/// Get the [`ApplicationHandler`] as mutable [`Any`].
///
/// This is required to be implemented when platform specific traits are desired.
#[inline(always)]
fn as_any(&mut self) -> Option<&mut dyn Any> {
None
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around a bit to figure out how we can get rid of this:
daxpedda@3740148

Mostly inspired by upcast.
I'm warming up to the VTable idea, but I couldn't find any documentation on how stable this is, so I'm unsure what the proposal around this was exactly.

Copy link
Member Author

@kchibisov kchibisov Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm warming up to the VTable idea, but I couldn't find any documentation on how stable this is, so I'm unsure what the proposal around this was exactly.

vtable is only for completely out of tree stuff, for regular staff you don't need vtables, since users will have Option<dyn Handler> and you can just if let it. But function pointers are completely safe and stable, there's nothing wrong with them and they are all completely safe code.

it's just in the current state of things I decided with vtable, since it won't affect other APIs and for entirely platform specific staff I'd use this approach unless we have separate crates.

We can have -> Option<&mut dyn MacOSApplicationHandler> from the ApplicationHandler itself already, and it's vtable free.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah okay, I was thinking of totally different things.
I would like to avoid having to use register_x() entirely. That is possible by unsafely reading the VTable and figuring out at runtime if a trait is implemented for a certain type.

@kchibisov
Copy link
Member Author

This is already present on master.

@kchibisov kchibisov closed this Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants