Bindgen: accept closure directly in event registration methods#4437
Merged
Conversation
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/95a464fb-b21d-436c-bd6a-0d3c480e2a01 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
kennykerr
May 20, 2026 00:01
View session
This was referenced May 28, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #4435: under
--minimal, event registration methods now take the handler closure directly and construct the delegate internally, so the delegate type can be inferred.Before:
After:
Changes
crates/libs/bindgen/src/types/method.rs— In theis_event_addbranch, detect theType::Delegateparameter and replace itsP{n}: Param<Delegate>generic withF: Fn(<delegate Invoke sig>) -> Result<()> + Send + 'static(reusingDelegate::method().write_impl_signatureso the bound matchesDelegate::new's constraint exactly). The body prependslet handler = <Delegate>::new(handler);(UFCS wrapper handles generic delegates likeTypedEventHandler<T, U>) and passesInterface::as_raw(&handler)to the vtable call. Non-delegate parameters keep their existing convertible /IReferencehandling. Falls back to the previous signature if no delegate parameter is found.crates/tests/libs/bindgen/data/bindgen/auto_events/expected.rs— Regenerated by the fixture.crates/tests/winrt/events_client/src/auto_bindings.rs— Regenerated via the crate'sbuild.rs.crates/tests/winrt/events_client/src/lib.rs— Auto-events test fixture from Add non-generic EventRevoker + --minimal bindgen event-revoker support #4435 updated to the closure-only syntax.