Open kennykerr opened 4 years ago
This might not be possible to do since conceptually we need to ensure methods which take delegates are generic over some type which is either a delegate which takes some type that implements FnMut
or another type which also implements the same FnMut
trait. I believe this would require higher-kinded types since the generic delegate type is itself generic over some type.
Challenge accepted. 🤜
Given that passing a closure is by far the most common scenario, we could make that the default and provide a XxxWithDelegate
"overload" for when you absolutely must pass an existing delegate object.
Closing this old issue - doesn't seem to be much demand for such API support. Let me know if you have thoughts to the contrary. 😊
Reopening as there's been some renewed interest in WinRT API support.
Rust/WinRT doesn't yet automatically bind a lambda/closure to a delegate parameter. Today you need to create the delegate yourself. It looks something like this:
In the future you should be able to write simply:
The difficulty is in somehow specializing the
winrt::Param
generic for delegates to automatically create a WinRT delegate as needed while still supporting delegate objects for pass-through.Alternatively, we could just use
FnMut
as the generic param for delegates. That would probably provide the best experience in most cases, but would suffer from "over-wrapping" delegate objects that are merely being passed through.