Skip to main content

WindowHandle

Trait WindowHandle 

Source
pub trait WindowHandle: HasWindowHandle + HasDisplayHandle { }
Expand description

A window/display handle pair, as one trait.

Presenters receive raw-window-handle types, not a concrete winit::window::Window: softbuffer, wgpu, and glutin all accept these handles directly, so any windowing library that produces them can drive the same presenter, and only this crate depends on winit itself.

raw-window-handle has no combined trait, and surface libraries need to own the handle (softbuffer stores it for the surface’s lifetime), so presenters receive Arc<dyn WindowHandle>: rwh implements the handle traits for Arc<H: ?Sized>, so the trait object passes straight into softbuffer::Surface::new / wgpu::Instance::create_surface.

§Examples

Blanket-implemented for any type implementing both raw-window-handle traits; there is nothing to implement directly on WindowHandle itself.

use raw_window_handle::{
    DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle,
    WindowHandle as RawWindowHandle,
};
use retroglyph_window::WindowHandle;

struct NoWindow;

impl HasWindowHandle for NoWindow {
    fn window_handle(&self) -> Result<RawWindowHandle<'_>, HandleError> {
        Err(HandleError::NotSupported)
    }
}

impl HasDisplayHandle for NoWindow {
    fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
        Err(HandleError::NotSupported)
    }
}

fn assert_is_window_handle<T: WindowHandle>(_handle: &T) {}
assert_is_window_handle(&NoWindow);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§