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

Prefer optional over convertible parameters #3368

Merged
merged 8 commits into from
Dec 9, 2024
Merged

Conversation

kennykerr
Copy link
Collaborator

Thanks to #3359, it's now a lot easier to reason about some of these more nuanced type scenarios. The windows-bindgen crate has traditionally overused the Param trait to provide cover for various weird Windows API-isms but the Param trait tends to be quite confusing when you don't get the parameters just right and in particular for APIs that don't expect polymorphism. In some cases its necessary - specifically for COM or WinRT polymorphism - but in particular it was previously used for all Win32 handle types which was almost always unnecessary.

This update does two things:

  • Avoid applying the Param trait for handle types
  • Detect more optional parameters and use Option<T> for copyable parameter types

When combined this limits the fallout from the first and generally makes the API surface more coherent as optional parameters are actually optional and the vast majority of handle types, which aren't convertible, are simple type parameters.

In some cases where "handle polymorphism" is actually expected by some API you can simply use the Into or From traits to perform the conversion.

Fixes: #3320

@kennykerr kennykerr changed the title Prefer optional params over convertible parameters Prefer optional over convertible parameters Dec 9, 2024
@kennykerr kennykerr merged commit b52ae04 into master Dec 9, 2024
75 checks passed
@kennykerr kennykerr deleted the prefer-optional-params branch December 9, 2024 22:21
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.

windows-bindgen should avoid Param traits as much as possible
1 participant