Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should windows::Storage::StorageFolder implement IntoParam<IStorageFolder> ? #2946

Closed
ldosen opened this issue Mar 22, 2024 · 8 comments
Closed
Labels
question Further information is requested

Comments

@ldosen
Copy link

ldosen commented Mar 22, 2024

Summary

This C++ sample, illustrates how to set the path field for the StorageProviderSyncRootInfo struct.

However, trying to set the path field similarly to the sample will fail to compile in Rust due to a trait bound error.

error[E0277]: the trait bound `StorageFolder: IntoParam<IStorageFolder, ReferenceType>` is not satisfied
    --> src\root.rs:38:13
     |
37   |           info.SetPath(
     |                ------- required by a bound introduced by this call
38   | /             StorageFolder::GetFolderFromPathAsync(&HSTRING::from(&self.path)
39   | |             )?
40   | |                 .get()?
     | |_______________________^ the trait `IntoParam<IStorageFolder, ReferenceType>` is not implemented for `StorageFolder`
     |
     note: required by a bound in `StorageProviderSyncRootInfo::SetPath`
    --> C:\Users\[user_name]\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.54.0\src\Windows\Storage\Provider\mod.rs:1438:13
     |
1436 |     pub fn SetPath<P0>(&self, value: P0) -> ::windows_core::Result<()>
     |            ------- required by a bound in this associated function
1437 |     where
1438 |         P0: ::windows_core::IntoParam<super::IStorageFolder>,
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StorageProviderSyncRootInfo::SetPath`

It seems like this method of setting the sync root path worked in an older version of this crate, though for what it's worth, I have not tried to compile this project.

Any help is appreciated, thanks.

Crate manifest

No response

Crate code

No response

@ldosen ldosen added the bug Something isn't working label Mar 22, 2024
@riverar riverar added question Further information is requested and removed bug Something isn't working labels Mar 22, 2024
@riverar
Copy link
Collaborator

riverar commented Mar 22, 2024

The error here is admittedly a bit non-intuitive, but you're probably missing feature Storage_Search in Cargo.toml. This will bring in the additional implementation of IStorageFolder needed here.

#[repr(transparent)]
#[derive(PartialEq, Eq, core::fmt::Debug, Clone)]
pub struct StorageFolder(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(StorageFolder, windows_core::IUnknown, windows_core::IInspectable);
#[cfg(feature = "Storage_Search")]
windows_core::imp::required_hierarchy!(StorageFolder, IStorageFolder, IStorageFolder2, Search::IStorageFolderQueryOperations, IStorageItem, IStorageItem2, IStorageItemProperties, IStorageItemProperties2, IStorageItemPropertiesWithProvider);
impl StorageFolder {

@kennykerr
Copy link
Collaborator

This is regrettable as the cfg here applies to the entire required hierarchy when there's only one required interface that is not from the current namespace.

@ldosen
Copy link
Author

ldosen commented Mar 22, 2024

@riverar
that did the trick, thanks!

@ldosen ldosen closed this as completed Mar 22, 2024
@riverar
Copy link
Collaborator

riverar commented Mar 22, 2024

I'd like to also add, you shouldn't need to use anything in Windows.Storage. Those APIs tend to be brokered and/or have all sorts of gotchas in non "UWP" scenarios. If you can share a bit more about what you're trying to do, we can probably point you to an equivalent Win32 API.

@kennykerr
Copy link
Collaborator

Also https://jonwis.github.io/notes/winrt-design/system_interfaces.html

@ldosen
Copy link
Author

ldosen commented Mar 25, 2024

I'd like to also add, you shouldn't need to use anything in Windows.Storage. Those APIs tend to be brokered and/or have all sorts of gotchas in non "UWP" scenarios. If you can share a bit more about what you're trying to do, we can probably point you to an equivalent Win32 API.

Thanks, I appreciate the help. I am looking to use the cloud files api instead of an older, less fully featured minifilter driver for an existing two-way syncing application. I want to make use of the shell integration features (custom state icons, extended metadata, progress indication, etc), and AFAIK, I need to call the Register method of the StorageProviderSyncRootManager class from the Windows.Storage.Provider namespace to use those features. But if you think I'd be able to use only Win32 APIs to do this, that would be great!

@kennykerr
Copy link
Collaborator

@jonwis may have some ideas.

@jonwis
Copy link
Member

jonwis commented Mar 25, 2024

The StorageProviderSyncRootManager interface only thinks in StorageFile today. Consider having your code think in Win32 APIs and paths as much as you care to, then use StorageFolder.GetFolderFromPathAsync to convert to the currency the API needs as the last step. Looks like you're already using that, which is as good as it gets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants