-
Notifications
You must be signed in to change notification settings - Fork 513
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
Support composable constructors #3242
Comments
OK, so the immediate issue here is that the Technically, it has a |
Thank you for such a quick response! Do I understand correctly that this means that in the current version I would essentially need to |
To call that constructor you need to use |
FYI as a workaround for now this seems to work: #[implement(PropertyChangedEventArgs)]
struct MyPropertyChangedEventArgs {
property_name: HSTRING,
}
impl MyPropertyChangedEventArgs {
fn new<T: AsRef<str>>(property_name: T) -> Self {
MyPropertyChangedEventArgs {
property_name: HSTRING::from(property_name.as_ref()),
}
}
}
impl IPropertyChangedEventArgs_Impl for MyPropertyChangedEventArgs_Impl {
fn PropertyName(&self) -> Result<HSTRING> {
Ok(self.property_name.clone())
}
} I guess that's because |
The trouble is that |
@kennykerr This works as expected, thank you very much! 🥇 I've noticed however that the factory function is public: #[doc(hidden)]
pub fn IPropertyChangedEventArgsFactory<
R,
F: FnOnce(&IPropertyChangedEventArgsFactory) -> windows_core::Result<R>,
>(
callback: F,
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<
PropertyChangedEventArgs,
IPropertyChangedEventArgsFactory,
> = windows_core::imp::FactoryCache::new();
SHARED.call(callback)
} This seems like an implementation detail so should probably be hidden from the user? 🤔 It's also a bit inconsistent that the constructor is named |
#3261 for the factory functions - good catch! Regarding https://github.com/microsoft/windows-rs/blob/master/crates/tests/winrt/constructors/src/metadata.idl |
You, sir, are an absolute hero! Thank you so much for addressing this! |
Suggestion
Hi,
I'm probably trying to do something forbidden 😅 but I think this is still a valid use case for the WinRT type system.
I'm looking at implementing a simple ViewModel with Rust that can then be used from a C# UI app.
I generate bindings as follows:
And then I implement the
INotifyPropertyChanged
interface by saving the handlers into a hash map:The issue is that, when firing handlers, I need to pass them an instance of
PropertyChangedEventArgs
. But the generated bindings don't contain a constructor for it, so there's no way for me to create a new instance:Am I missing something? Or are events and event args not supported too?
Please ignore the WinUI use case. Events are a part of the WinRT type system, so I believe they should be available to the users of windows-rs.
Thank you!
The text was updated successfully, but these errors were encountered: