The trait `raw_window_handle::HasRawDisplayHandle` is not implemented for `Window` [closed]
Asked Answered
N

1

8

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.

Nodical answered 27/10, 2023 at 10:30 Comment(1)
Please add a minimal reproducible example.Disentomb
R
14

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.

Ruthven answered 27/10, 2023 at 14:34 Comment(1)
Excellent, this is exactly correct. Although, I hear lots of talk of part of the wonder of cargo taking care of dependencies for you. Is there a cargo way of resolving this automatically? like telling cargo to use all features or somethingJackjackadandy

© 2022 - 2024 — McMap. All rights reserved.