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

Add safe path from T: HasRawWindowHandle to TrustedHandle #66

Closed
DJMcNab opened this issue Jan 23, 2021 · 2 comments
Closed

Add safe path from T: HasRawWindowHandle to TrustedHandle #66

DJMcNab opened this issue Jan 23, 2021 · 2 comments

Comments

@DJMcNab
Copy link

DJMcNab commented Jan 23, 2021

It seems to me that the requirements of TrustedHandle::new being correct are exactly that the handle matches the invariants on HasRawWindowHandle, i.e.

impl TrustedWindowHandle {
    fn from_handle<T: HasRawWindowHandle>(has_handle: &T){
        // Safe: `impl HasRawWindowHandle` requires that `raw_window_handle`
        // returns a valid handle
        unsafe { Self::new(has_handle.raw_window_handle()) };
    }
}

would be valid (and useful)

Original comment from (#52 (comment))


Would it be possible to have a safe impl of new or equivalent for any T: HasRawWindowHandle?

Specifically, an implementation which would replace https://github.com/bevyengine/bevy/blob/a68c78cef5fb2112617de095efd4e64cba1587eb/crates/bevy_winit/src/winit_windows.rs#L117-L119

(I need this for bevyengine/bevy#1279, which is currently assuming that the impl could be correct, so I would like to know if that assumption is wrong anyway. That PR is otherwise blocked on #58 anyway)

@Lokathor
Copy link
Contributor

This seems good. I might have time to work on this crate during this weekend/Monday, and if so I can do this easily.

@DJMcNab
Copy link
Author

DJMcNab commented Jan 23, 2021

Excellent, I just wanted to sanity check that I wasn't missing any reason that wouldn't work.

Lokathor added a commit that referenced this issue Jan 25, 2021
@Lokathor Lokathor closed this as completed Feb 5, 2021
Lokathor added a commit that referenced this issue Jun 5, 2021
* ready for a breaking version.

* Closes #66

* changelog.

* remove cfg guards on the modules and variants.

* changelog.

* fix the doctest typo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants