How can i do default of SHFILEINFOW

i want to use SHFILEINFOW of shellapi,but can't default。

error[E0277]: the trait bound SHFILEINFOW: std::default::Default is not satisfied
--> src\main.rs:63:19
|
63 | let mut shfi = Default::default();
| ^^^^^^^^^^^^^^^^ the trait std::default::Default is not implemented for SHFILEINFOW

thanks for you help。

Where did you find this definition?

With the following dependency in Cargo.toml:

windows = { version = "0.44.0", features = ["Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }

I tried to build the following:

fn main() {
  let a = windows::Win32::UI::Shell::SHFILEINFOW::default();
}

And it built just fine on my Windows 11 system.

The image isn't loading for me so I can only guess but if you're wanting to use the winapi crate then you'd have to enable the impl-default feature.

thank you,but the create i want to used is

let mut shfi = winapi::um::shellapi::SHFILEINFOW::default();

the error is :
no function or associated item named default found for struct SHFILEINFOW in the current scope
function or associated item not found in SHFILEINFOW

You need to add the impl-default feature to the winapi dependency in your Cargo.toml.

1 Like

I just started to contact Rust. Could you give me an example? Thank you。

use winapi::um::shellapi::SHFILEINFOW;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.