1

I am using Rust and the windows-rs crate to access the Windows API from Rust.

As input, I have an Vec<String> which I want to convert into an IIterable<HSTRING>. According to this ticket, it should be possible to use the try_from trait.

Here is what I've tried:

let hStringVector: Vec<HSTRING> = stringVector.iter().map(|c| HSTRING::from(c)).collect()?; 
let storeidsWin = IIterable::<HSTRING>::try_from(storeIdsWinRaw);

But this gives me the following error:

error[E0277]: the trait bound `IIterable<HSTRING>: From<Vec<HSTRING>>` is not satisfied
   --> src\lib.rs:104:58
    |
104 |         let storeidsWin = IIterable::<HSTRING>::try_from(hStringVector);
    |                           ------------------------------ ^^^^^^^^^^^^^ the trait `From<Vec<HSTRING>>` is not implemented for `IIterable<HSTRING>`
    |                           |
    |                           required by a bound introduced by this call
    |
    = note: required for `Vec<HSTRING>` to implement `Into<IIterable<HSTRING>>`
    = note: required for `IIterable<HSTRING>` to implement `TryFrom<Vec<HSTRING>>`

Unfortunately I am new to Rust and don't know what this error wants to tell me (and how to fix it).

Dominic
  • 4,572
  • 3
  • 25
  • 36
  • I think you might need to check impls of `IIterable` to see how can it convert from `Vec`. [Code](https://github.com/microsoft/windows-rs/blob/a98ae0578b787e67546303186b46494f0c0a7a46/crates/tools/riddle/src/rust/extensions/impl/Foundation/Collections/Iterable.rs#L86C1-L86C1) shows the restriction of `T`. No idea whether `HSTRING` has these traits. – Campbell He Jul 18 '23 at 01:57

0 Answers0