Skip to content

Bindgen: accept closure directly in event registration methods#4437

Merged
kennykerr merged 2 commits into
masterfrom
copilot/update-event-registration-method
May 20, 2026
Merged

Bindgen: accept closure directly in event registration methods#4437
kennykerr merged 2 commits into
masterfrom
copilot/update-event-registration-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

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:

let routed = Xaml::RoutedEventHandler::new(move |_sender, _args| Ok(()));
let revoker = source.Click(&routed)?;

After:

let revoker = source.Click(move |_sender, _args| Ok(()))?;

Changes

  • crates/libs/bindgen/src/types/method.rs — In the is_event_add branch, detect the Type::Delegate parameter and replace its P{n}: Param<Delegate> generic with F: Fn(<delegate Invoke sig>) -> Result<()> + Send + 'static (reusing Delegate::method().write_impl_signature so the bound matches Delegate::new's constraint exactly). The body prepends let handler = <Delegate>::new(handler); (UFCS wrapper handles generic delegates like TypedEventHandler<T, U>) and passes Interface::as_raw(&handler) to the vtable call. Non-delegate parameters keep their existing convertible / IReference handling. 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's build.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.

@kennykerr kennykerr merged commit 373023f into master May 20, 2026
28 checks passed
@kennykerr kennykerr deleted the copilot/update-event-registration-method branch May 20, 2026 00:20
This was referenced May 28, 2026
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.

2 participants