Skip to content

Add safe path from T: HasRawWindowHandle to TrustedHandle #66

@DJMcNab

Description

@DJMcNab

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions