rust-windowing / raw-window-handle

A common windowing interoperability library for Rust
Apache License 2.0
326 stars 50 forks source link

Add safe constructors for display and window handles #156

Open notgull opened 1 year ago

notgull commented 1 year ago

There are some DisplayHandle and WindowHandle variants that are completely safe to construct. For instance:

It should be possible to construct these safely, with constructors on the safe types.

kchibisov commented 1 year ago

The reason everything in unsafe is forward compat, I guess? Because unsafe -> safe is a breaking change, but not otherwise.

kchibisov commented 1 year ago

Also, isn't Default basically it?

notgull commented 1 year ago

I was thinking more along these lines:

impl DisplayHandle<'static> {
    pub fn windows() -> Self {
        unsafe { Self::borrow_raw(WindowsDisplayHandle::new().into()) }
    }

    pub fn xlib_no_display() -> Self {
        unsafe { Self::borrow_raw(XlibDisplayHandle::new(None).into()) }
    }
}

Basically, to allow for more ways of creating DisplayHandle and WindowHandle without needing to go through borrow_raw.