Search code examples
rustwindowwgpu-rswinit

The trait `raw_window_handle::HasRawDisplayHandle` is not implemented for `Window`


When I try to make a wgpu surface I get this error:

error[E0277]: the trait bound `Window: raw_window_handle::HasRawDisplayHandle` is not satisfied
    --> src/lib.rs:34:56
     |
34   |         let surface = unsafe { instance.create_surface(&window) }.unwrap();
     |                                         -------------- ^^^^^^^ the trait `raw_window_handle::HasRawDisplayHandle` is not implemented for `Window`
     |                                         |
     |                                         required by a bound introduced by this call
     |
     = help: the following other types implement trait `raw_window_handle::HasRawDisplayHandle`:
               &'a T
               raw_window_handle::borrowed::DisplayHandle<'_>

this my code:

let surface = unsafe { instance.create_surface(&window) }.unwrap();

i dont know how fix that, i try fix but everything is in vain.


Solution

  • The function create_surface takes an argument window which must implement HasRawWindowHandle + HasRawDisplayHandle

    Your code is correct, but you are missing a/the winit **rwh_05** feature.

    Replace winit = "0.29" with winit = { version = "0.29", features = ["rwh_05"]} in the Cargo.toml file and it should work.