Add safe path from T: HasRawWindowHandle to TrustedHandle
DJMcNab opened this issue · 2 comments
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)
This seems good. I might have time to work on this crate during this weekend/Monday, and if so I can do this easily.
Excellent, I just wanted to sanity check that I wasn't missing any reason that wouldn't work.