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

Basic delegate support #130

Merged
merged 25 commits into from
May 7, 2020
Merged

Basic delegate support #130

merged 25 commits into from
May 7, 2020

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented May 7, 2020

WinRT delegates are COM interfaces that behave like function objects. They are used as callbacks for some APIs but overwhelmingly used to implement events and are thus required by many Windows APIs.

Much like WinRT interfaces, delegates may be generic and non-generic and like interfaces, generic delegates require GUIDs derived from their generic arguments. This update provides basic support for delegates and while you can call a generic delegate, you cannot use it with any API that might attempt to query its GUID. That's why I need to add support for #129 to unblock full use of delegates and then a ton more Windows APIs will suddenly light up.

Delegates also give the first taste of authoring support in Rust. Full authoring support will come later #81 and includes the ability to author WinRT classes and interfaces. For now, delegates represent a very simple form of type authoring as they require the caller to provide an implementation of the delegate's underlying COM interface. The implementation details need some improvement but this will unblock me to work on some of the other prerequisites as we move toward getting more of the type system online.

There are also a few usability issues that I still need to address.

  • Delegates whose closures don't (wish to) propagate failure should be able to avoid the trailing Ok(()).
  • API parameters that expect a delegate should be able to accept a closure directly rather than having the caller wrap it in DelegateName::new(|| ...) as that can be quite tedious.
  • I should be able to call a delegate like a function object e.g. delegate(a, b, c) instead of delegate.invoke(a, b, c).

So room for improvement, but at least here we have the ABI roughed in so we can start building on this.

Fixes #72

@kennykerr kennykerr requested a review from rylev May 7, 2020 19:30
@kennykerr kennykerr merged commit a036b8e into master May 7, 2020
@kennykerr kennykerr deleted the kennykerr branch May 7, 2020 21:27
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.

Need support for implementing delegates
1 participant