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

Stock collection support for IIterable #2346

Merged
merged 9 commits into from
Feb 23, 2023
Merged

Stock collection support for IIterable #2346

merged 9 commits into from
Feb 23, 2023

Conversation

kennykerr
Copy link
Collaborator

As part of #91, this update provides the groundwork to support stock collections and introduces TryFrom for IIterable<T> as a start. Stock implementations of the remaining collection types will follow. In its simplest form, you can write the following:

let collection = IIterable::<i32>::try_from(vec![1, 2, 3])?;

Along with building on the type trait support and implement macro improvements in #2343, this update fixes a few things that have become increasingly difficult to work around. Notably, most of the internal implementation details of the windows crate are now moved to the windows::imp module rather than the windows::core module that provides public supporting types. Previously these types and helpers were simply hidden from documentation, but this change makes it more obvious what's an implementation detail to be avoided as opposed to simply missing documentation. Conversely, it will make it easier to figure out what needs documenting.

@kennykerr kennykerr merged commit 84c8649 into master Feb 23, 2023
@kennykerr kennykerr deleted the stock-base branch February 23, 2023 17:37
mod Windows;

#[doc(hidden)]
pub mod imp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a technical reason why this cannot be

pub(crate) mod imp;

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are implementation details that are nevertheless used outside of the windows crate because the windows-bindgen crate will generate them for non-Windows metadata.

This was referenced Feb 24, 2023
@Jamzy01
Copy link

Jamzy01 commented Nov 17, 2023

Hi, do I need to enable a feature flag in the Cargo.toml file or something to use this feature? Because the rust compiler won't recognize my conversion.

let collection = IIterable::<i32>::try_from(vec![1, 2, 3])?;

returns this error

error[E0277]: the trait bound `IIterable<i32>: std::convert::From<Vec<{integer}>>` is not satisfied
   --> src\file_system_object\clipboard_handler\mod.rs:280:26
    |
280 |         let collection = IIterable::<i32>::try_from(vec![1, 2, 3])?;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<Vec<{integer}>>` is not implemented for `IIterable<i32>`
    |
    = note: required for `Vec<{integer}>` to implement `Into<IIterable<i32>>`
    = note: required for `IIterable<i32>` to implement `TryFrom<Vec<{integer}>>`

@kennykerr
Copy link
Collaborator Author

You need the implement feature.

@Jamzy01
Copy link

Jamzy01 commented Nov 19, 2023

Hi there, sorry but I'm still struggling to understand how this works, so I'm trying to set the clipboard contents like this:

let new_clipboard_data = DataPackage::new().unwrap();

let mut clipboard_items = Vec::new();

clipboard_items.push(Some(FileSystemLocation::load_from_string("J:\\Test").unwrap()));

new_clipboard_data
    .SetStorageItems(
        &IIterable::<IStorageItem>
            ::try_from(clipboard_items)
            .expect("Failed to convert clipboard items to IIterable"),
        false
    )
    .expect("Failed to set clipboard storage items");

Clipboard::SetContent(&new_clipboard_data).unwrap_or_else(|err|
    eprintln!("Failed to set clipboard data {err}")
);

And FileSystemLocation implements IStorageItem_Impl, except it still gives me this error:

error[E0277]: the trait bound `windows::Foundation::Collections::IIterable<windows::Storage::IStorageItem>: std::convert::TryFrom<std::vec::Vec<std::option::Option<file_system_location::FileSystemLocation>>>` is not satisfied
   --> src\file_system_object\clipboard_handler\mod.rs:291:18
    |
291 |                   &IIterable::<IStorageItem>
    |  __________________^
292 | |                     ::try_from(clipboard_items)
    | |______________________________^ the trait `std::convert::TryFrom<std::vec::Vec<std::option::Option<file_system_location::FileSystemLocation>>>` is not implemented for `windows::Foundation::Collections::IIterable<windows::Storage::IStorageItem>`
    |
    = help: the trait `std::convert::TryFrom<std::vec::Vec<<T as windows::core::Type<T>>::Default>>` is implemented for `windows::Foundation::Collections::IIterable<T>`

I assume passing IStorageItems themselves would work, except from what I can gather, I cannot create these objects myself, besides there must be a reason why IStorageItem_Impl exists anyway. One more thing, are there even any examples of something like this?

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

Successfully merging this pull request may close these issues.

3 participants