Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: Add a safe method for cross-crate interop to winit #2744
feat: Add a safe method for cross-crate interop to winit #2744
Changes from 8 commits
59a4144
c3616e1
a735cd9
1db45e2
2e9b655
902a8ca
6bdb342
61e4180
1fcc441
506f08c
0767b89
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I don't really understand the purpose of this type. The
EventLoop
itself is what should have theHasDisplayHandle
impl, and its lifetime is what should be used. The fact that you're not using this type in examples at all suggests me that there's no clear case when it should be used(at least you should use it inside the examples).The
EventLoopWindowTarget
must have the same lifetime as theEventLoop
itself, because it's simply a field onEventLoop
in all the backends.The
Clone
is also sort of questionable, because it simply will discard the lifetime attached to it, given that there's only a way to get&OwnedDisplayHandle
not the owned type on its own?if that's intent on
lifetime
casting, different method should be used withunsafe
bit on it(because it's simplymem::tranmsute
like thingy of donig'static
lifetime).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.
The reason why this type exists is for the
glutin
case. The scenario is that you need an object that has a display handle before a window is created, since you need to query the display. You can't useEventLoop
,&EventLoop
or aDisplayHandle<'_>
taken from anEventLoop
because theEventLoop
is owned/borrowed mutably for event handling. You can't use theEventLoopWindowTarget
that is provided in the event handler, since it disappears between events, which means it can't be used persistently. Normally I'd use aWindow
, but forglutin
(outside of Win32) you haven't created aWindow
yet.Therefore I created this type to fill that hole. Something that implements
HasDisplayHandle
that can be used according to Rust's borrowing system. This way, it can be used in the display position without any unsafe hacks.If theactually, it might be necessary for the borrowing rules to check out in this case.Clone
is a deal breaker I can get rid of it.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.
I just think that it's
unsafe
, so you might have different method liketo_static
, which casts away lifetime.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.
I have added documentation clarifying the purpose of
OwnedWindowHandle
and why it is safe.